• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 882
  • Last Modified:

ASP.net VB.net post a string to an http server using some kind of http client using post method

Hi

In ASP.net VB.net how do I post a string to an http server using the post method. I was given the following link which helped but I still can't get my head around how to do this.
The java code below is an example of what I need to do in VB.net

http://www.codeproject.com/Articles/18034/HttpWebRequest-Response-in-a-Nutshell-Part-1

  try {

      // This will Post the xml string data...    
      URL url = new URL("http://IPAddress:Port/APIWebModule/APIServlet");
      HttpURLConnection connection = (HttpURLConnection)url.openConnection();
      connection.setRequestMethod("POST");
      connection.setDoOutput(true);
      PrintWriter out = new PrintWriter( connection.getOutputStream());
      String data = "The XML string request";
      out.print(data);
      out.flush();
      out.close();



      // This will read the XML response data...
      InputSource inSource = new InputSource(connection.getInputStream());
      DOMParser dp = new DOMParser();
      dp.parse(inSource);
      Document doc = dp.getDocument();
      // This gives you an XML DOM document to work with
     
    }
    catch (SAXException ex) {
    }
    catch (MalformedURLException ex) {
    }
    catch (IOException ex) {
    }
0
Murray Brown
Asked:
Murray Brown
1 Solution
 
käµfm³d 👽Commented:
Why not just use the WebClient class? There is the UploadString method which sounds like what you are trying to do:

Dim data As String = "The XML string request"
Dim serverResponseHTML As String

Using wc As New System.Net.WebClient()
    serverResponseHTML = wc.UploadString("http://IPAddress:Port/APIWebModule/APIServlet", data)
End Using

Open in new window

0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much. I'll give that a try
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now