Invoking the url and adding the string to the url

laxman

Freshman
Joined
Jun 14, 2008
Messages
28
i am developing the Windows application using VB.Net here i need to transfer some information to the my customer server and he will be replying to the information acknowledgement. for this my customer given a url and asked me to invoke the url and add the information as a string. here i dont know how to invoke this url and add string so please guide me what i should do and my customer said he will be acknowledged me with the out put i also dont know how to capture the acknowledgement i can give the url ends with ip/web/servlet so please tell me how can i do this
 
Without knowing exactly what format the request and response take it is a bit difficult to give any exact advice.

Could you show the url format / response format?
 
Try something like this

Visual Basic:
Imports System
Imports System.IO
Imports System.Net
Module Module1 
    Sub Main()
       'Address of URL
         Dim URL As String = "http://customer.com/customerURL.ext?query=String"
        ' Get HTML data
        Dim client As WebClient = New WebClient()
        Dim data As Stream = client.OpenRead(URL)
        Dim reader As StreamReader = New StreamReader(data)
        Dim str As String = ""
        str = reader.ReadLine()
        Do While str.Length > 0
            Console.WriteLine(str)
            str = reader.ReadLine()
        Loop
        End Sub
End Module

Also, try this link where the above sample came from. There are additional samples available here.

I cannot tell from your description; however, if your customer is trying to have you use a webservice they have, all you need to do is add the URL they provide as a "Web Reference" to your application.
 
Request and Responce will be in XML formate here i am sending the details
it is a private ip http://156.0.11.27/webmethod/servelet
and i need to add XML file for the above url in this formate
<Request>
<Transaction ID>101</Transaction ID>
<User Name>LAX</User Name>
</request>

They will acknowledge me by this XML formate
<Acknowledge>
<Transaction ID>101</Transaction ID>
<Status>0</Status>
</Acknowledge>

Thank You for the reply
 
i tried with the code i am getting an error The Remote Server returned an error (404) Not Found can any one tell what may be went wrong my code is

Visual Basic:
Dim request As WebRequest = WebRequest.Create("http://156.0.11.27:9080/Update/UpdateServlet?<RequestXml><MachineIp>10.0.0.1</MachineIp><TransactionId>110</ TransactionId ><RequestTime>24/06/2008 12:02:40 PM</RequestTime>(MM/DD/YYYY H:MI:SS)</RequestXml>")


        request.Method = "POST"
        Dim postData As String = "This is a test that posts this string to a Web server."
        Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
        Dim instance As New WebException
        Dim value As WebExceptionStatus
        request.ContentType = "application/x-www-form-urlencoded"
        request.ContentLength = byteArray.Length
        Dim dataStream As Stream = request.GetRequestStream()
        dataStream.Write(byteArray, 0, byteArray.Length)
        ' Close the Stream object.
        dataStream.Close()
        ' Get the response.
        value = instance.Status
        Dim response As WebResponse = request.GetResponse()
        ' Display the status.
        Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
        ' Get the stream containing content returned by the server.
        dataStream = response.GetResponseStream()
 
Last edited by a moderator:
As PD pointed out, 404 indicates that the URL itself is incorrect.


If the URL is correct, and the page expect the data as a "POST"

try these modifications:
Visual Basic:
Dim request As WebRequest = _
    WebRequest.Create("http://156.0.11.27:9080/Update/UpdateServlet/")


        request.Method = "POST"
        Dim postData As String = "<RequestXml><MachineIp>10.0.0.1</MachineIp><TransactionId>110</ TransactionId ><RequestTime>24/06/2008 12:02:40 PM</RequestTime>(MM/DD/YYYY H:MI:SS)</RequestXml>"

        Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
        Dim instance As New WebException
        Dim value As WebExceptionStatus
        request.ContentType = "application/x-www-form-urlencoded"
        request.ContentLength = byteArray.Length
        Dim dataStream As Stream = request.GetRequestStream()
        dataStream.Write(byteArray, 0, byteArray.Length)
        ' Close the Stream object.
        dataStream.Close()
        ' Get the response.
        value = instance.Status
        Dim response As WebResponse = request.GetResponse()
        ' Display the status.
        Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
        ' Get the stream containing content returned by the server.
        dataStream = response.GetResponseStream()
 
Hai Thank You The service expecting the XML as post method and i tried with the coding It is working fine thank you for every one
 
Back
Top