wavded / ogre

ogr2ogr geojson-focused web client
http://ogre.adc4gis.com
MIT License
266 stars 78 forks source link

Unable to send via .net WebRequest #54

Closed evermanwa closed 7 years ago

evermanwa commented 8 years ago

I have been pulling my hair out for some time now trying to send over a .net connection. I using the following code below but it keeps coming back with a "bad request" error. I'm not sure what it's having an issue with. Is this an issue with my request format or the webserver?

Example: Stream responseStream = response.GetResponseStream();

            byte[] rawData = ConvertToByteArray(responseStream);
            using (HttpClient client = new HttpClient())
            {
                using (MultipartFormDataContent formData = new MultipartFormDataContent())
                {
                    formData.Add(new ByteArrayContent(rawData, 0, rawData.Length), "Upload");
                    using (var message = await client.PostAsync("http://ogre.adc4gis.com/convert", formData))
                    {
                        var result = await message.Content.ReadAsStreamAsync();
                    }
                }
            }

Any insight or better way to do it would be much appreciated. Thanks!

evermanwa commented 8 years ago

My stream I am uploading is a kml file.

wavded commented 7 years ago

I do not know .NET so I was hoping someone else with experience would be able to assist you. Did you find a resolution @evermanwa ?

evermanwa commented 7 years ago

Hello wavded,

Sorry it took so long to reply, but yes I eventually tried a different tactic and this worked. Thanks!

Regards, William

evermanwa commented 7 years ago
            using (WebClient client = new WebClient())
            {
                var prms = new System.Collections.Specialized.NameValueCollection();
                prms.Add("json", json);

                byte[] response = client.UploadValues("http://ogre.adc4gis.com/convertJson", "POST", prms);

                return response;
            }