views:

23

answers:

1

I have a web service sitting on a dev machine written in python. I am trying to access said webservice using asp.net via the server side. the webservice has been tested and works in every other instance. but when I hit it via asp.net using a post method asp.net doesn't seem to be sending the post values to the webservice at all, everything else is sent fine. If I run the exact same code in a console application everything works 100%.

using System;
using System.IO;
using System.Net;
using System.Web;
using System.Text;

class WebService {
    static public String GetContent(String user_id, String content_id) {
        Uri address = new Uri("http://url.to.api/");
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
        String response_text = String.Empty;

        // Set type to POST  
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.Credentials = new NetworkCredential("username", "password");

        string data = string.Format("userid={0}&contentid={1}", user_id, content_id);
        byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
        request.ContentLength = byteData.Length;

        using (Stream postStream = request.GetRequestStream()) {
            postStream.Write(byteData, 0, byteData.Length);
        }

        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
            StreamReader reader = new StreamReader(response.GetResponseStream());
            response_text = reader.ReadToEnd();
        }

        return response_text;
    }
}
  • updated * with the class more or less thats being used. "url, user/pass".

Also we have checked the information going back and fourth and the webservice never sees the post data... this code as is ran on both a console app and in a asp.net project both hit the webservice, both get a response. the console gets a response with valid information showing that its working, the asp.net project runs and receives and error stating that userid isn't being passed. We have dozens of other sites hitting this webservice with no issues, except non are written in asp.net.

A: 

Use a proxy such as Fiddler to view the HTTP transaction between your app and the web service. That should give you a better idea of which end the error is on, and its nature.

You may consider running this against a test "Hello World" service just to test communcations.

Also, post your real code. Change the uri if you want, but what you've quoted above won't compile. The problem may be outside of this snippet.

update

How long is it taking for you to receive a reply? Timeout? Running out of connections?

David Lively
in both cases (asp.net, console) the reply is almost instant. the webservice is setup that if no userid or contentid is present that it returns a response stating as such, rather then a general 500 error.
Ropsody