Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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
Posted

Try something like this

 

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.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

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

Posted (edited)

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

 

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()

Edited by PlausiblyDamp
  • Administrators
Posted

If you browse direct to http://156.0.11.27/webmethod/servelet what happens? A 404 result would indicate that the URL itself doesn't exist / is misspelled rather than any problem with the code itself.

 

Is the remote site expecting the xml to be appended to the url or sent as a POST or even a SOAP request?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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:


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()

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...