none
HTTP Client - getting data from a GET request. RRS feed

  • Question

  • Hello,

    I want to retrieve some data using the HTTP protocol. The server has already been setup to recieve a customer ID. However, I am not sure about the http request in C#.

    I have been looking into the WebClient and the httpWebRequest clients. But I am not sure of the complete syntax.

    Below is the format of the GET REQUEST.

    HTTP GET /billing/servlet/comm.billing.GetBalance?Date=17:54:24&CustomerID=8057 HTTP/1.1

    However, I am not sure how to write the client to retrieve the data. The data returned is a float value.

    Many thanks,



    Tuesday, July 15, 2008 11:21 AM

Answers

  •  Your URL does require Http. So your code would be like this

    HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://000.000.00.00:8080/billing/servlet/comm.billing.GetBalance?Date=17:54:24&CustomerID=8057");     
     

    I would advise you to try your url from Internet Explorer. And paste the working Url in the above code.
    Gaurav Khanna
    • Marked as answer by steve1_rm Wednesday, July 16, 2008 4:23 AM
    Wednesday, July 16, 2008 3:46 AM

All replies

  • Try this code

     Dim wr As HttpWebRequest = WebRequest.Create("URI PATH")  
     Dim res As HttpWebResponse = wr.GetResponse  
     Dim br As New StreamReader(res.GetResponseStream)  
     Dim output As String = br.ReadToEnd 

    Gaurav Khanna
    Tuesday, July 15, 2008 12:11 PM
  • Hello,

    Thanks for the response.

    However, I am getting an error message with the code I am using below: "Invalid URI: The URI scheme is not valid."

    From what I can make out by using wireshark is that the server expects a customerID and the balance will be returned. I am not sure that the data is another parameter that the server expects.

    So how can I write the URL that expects a parameter like the customer ID?

    Many thanks for any extra help,



    private void btnGetBalance_Click(object sender, EventArgs e)  
    {  
    try 
    {  
    HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("000.000.00.00:8080/billing/servlet/comm.billing.GetBalance?Date=17:54:24&CustomerID=8057");  
    HttpWebResponse res = (HttpWebResponse)wr.GetResponse();  
    StreamReader sr = new StreamReader(res.GetResponseStream());  
    string balance = sr.ReadToEnd();  
    }  
    catch(UriFormatException ex)  
    {  
    MessageBox.Show(ex.Message);  
    }  
    catch(Exception ex)  
    {  
    MessageBox.Show(ex.Message);  
    }  
    }  
     
    Wednesday, July 16, 2008 3:33 AM
  •  Your URL does require Http. So your code would be like this

    HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://000.000.00.00:8080/billing/servlet/comm.billing.GetBalance?Date=17:54:24&CustomerID=8057");     
     

    I would advise you to try your url from Internet Explorer. And paste the working Url in the above code.
    Gaurav Khanna
    • Marked as answer by steve1_rm Wednesday, July 16, 2008 4:23 AM
    Wednesday, July 16, 2008 3:46 AM
  • Looks like you just beat me to it.

    I missed of the http://

    Thanks,

    Wednesday, July 16, 2008 4:23 AM