locked
Convert PHO to VB.net RRS feed

  • Question

  • User1536523983 posted

    Hi

    Could anyone please convert this PHP code to vb.net?

    "StringBuffer sb = getOffer("resources/jobfeedoffer.xml");
    String user = "user"; //provided by StepStone
    String password = "password"; //provided by StepStone
    String xmlresponse = "true";
     
    String urlParameters = "username="+user+"&pwd="+password+
        "&xmlresponse="+xmlresponse+"&xmlfile="+sb.toString();
    String request = "http://jobfeed.stepstone.com/listing/httpxml.cfm.utf-8";
    URL url = new URL(request);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setInstanceFollowRedirects(false);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.setRequestProperty("charset", "utf-8");
    connection.setRequestProperty("Content-Length", ""+Integer.toString(urlParameters.getBytes().length));
    connection.setUseCaches (false);
     
    OutputStream os = connection.getOutputStream();
    os.write(urlParameters.getBytes());"

    Wednesday, April 19, 2017 9:55 AM

All replies

  • User281315223 posted

    This looks like C#, not PHP.

    Anyways, you can use Telerik's C# to Visual Basic converter for this:

    StringBuffer sb = getOffer("resources/jobfeedoffer.xml");
    Dim user= "user"
    Dim password = "password"
    Dim xmlresponse = "true"
    
    Dim urlParameters As = string.Format("username={0}&pwd={1}&xmlresponse={2}&xmlfile={3}", user, password, xmlresponse, sb)
    Dim request = "http://jobfeed.stepstone.com/listing/httpxml.cfm.utf-8"
    
    Dim url As New URL(request)
    Dim connection As HttpURLConnection = DirectCast(url.openConnection(), HttpURLConnection)
    connection.setDoOutput(True)
    connection.setDoInput(True)
    connection.setInstanceFollowRedirects(False)
    connection.setRequestMethod("POST")
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
    connection.setRequestProperty("charset", "utf-8")
    connection.setRequestProperty("Content-Length", urlParameters.GetBytes().Length)
    connection.setUseCaches(False)
    
    OutputStream os = connection.getOutputStream();
    os.write(urlParameters.GetBytes());

    Wednesday, April 19, 2017 2:10 PM
  • User1536523983 posted

    I'm still struggling with this, don't think it's converting properly.

    Wednesday, May 17, 2017 1:30 PM
  • User475983607 posted

    I'm still struggling with this, don't think it's converting properly.

    It looks like Java not PHP.  You'll want to lookup the Java methods so you know what they do then you can map the concept to .NET libraries.

    Anyway, the key here is to take a moment to understand what you are trying to accomplish and not blindly rely on converting code from one syntax to another.  If you don't know what is supposed to happen how will you troubleshoot issues? 

    The first line of code is a bit of a mystery and I assume it is parsing an XML file into name/value pairs appended to the other parameters in the HTTP POST.

    String urlParameters = "username="+user+"&pwd="+password+
        "&xmlresponse="+xmlresponse+"&xmlfile="+sb.toString();

    The reset of the code is further setting up and submitting an HTTP Post.

    To do this in ASP...

    https://msdn.microsoft.com/en-us/library/debx8sh9(v=vs.110).aspx

    In the example above the snippet is sending data in the post collection as...

    string postData = "This is a test that posts this string to a Web server."; 

    You need to send the data as name/value pairs similar to the Java example.  

    Wednesday, May 17, 2017 1:49 PM