Trying to push a service alert feed in C#

165 views
Skip to first unread message

Deepak Nair

unread,
Jul 27, 2018, 2:40:35 PM7/27/18
to GTFS-realtime

Hi, I am trying to publish my service alert data using the push delivery method and as per the documentation, trying to execute the below curl request in C# and I am not getting any response back. Tried executing the curl request as well, again no response. Can someone here point out if I am missing anything here.


Curl:-

curl \

--header "authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-F "alkali_application_name=transit" \
-F "alkali_account_id=[your account id (*)]" \
-F "alkali_upload_type=realtime_push_upload" \
-F "alkali_application_id=xxxxxxx" \
-F "realtime_feed_id=[your realtime feed_name e.g. us-myfeed-updates]" \
-F "file=@/path/to/file" \
[https://partnerdash.google.com/push-upload](https://partnerdash.google.com/push-upload)

C# Code:-

  HttpClient httpClient = new HttpClient();
        httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "xxxxx");
        MultipartFormDataContent form = new MultipartFormDataContent();

        form.Add(addStringContent("alkali_application_name", "transit"));
        form.Add(addStringContent("alkali_account_id", "xxxx"));
        form.Add(addStringContent("alkali_upload_type", "realtime_push_upload"));
        form.Add(addStringContent("alkali_application_id", "xxxxx"));
        form.Add(addStringContent("realtime_feed_id", "xxxxx"));
        form.Add(addStreamContent(alertStream, "xxxxx.txt"));

        HttpResponseMessage response = await httpClient.PostAsync("https://partnerdash.google.com/push-upload", form);

private static StreamContent addStreamContent(Stream stream, string filename)
    {
        var fileContent = new StreamContent(stream);
        fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
        {
            Name = "\"file\"",
            FileName = "\"" + filename + "\""
        };
        fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
        return fileContent;
    }
    private static StringContent addStringContent(string name, string content)
    {
        var fileContent = new StringContent(content);
        fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
        {
            Name = "\"" + name + "\""
        };
        return fileContent;
    }
Reply all
Reply to author
Forward
0 new messages