Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Following is the java code but I get response only "OK"
while I am using Vb.net with same API I got response "SMS Sent Successfully"


JAVA CODE

String requestUrl = "SOME API";

URL url = new URL(requestUrl);
HttpURLConnection uc = (HttpURLConnection)url.openConnection();

System.out.println(uc.getResponseMessage());

uc.disconnect();


VB.net COde
Imports System.Net
Imports System.IO

Dim sURL As String
Dim objReader As StreamReader
Dim objStream As Stream
Dim sResponse As WebRequest

sResponse = WebRequest.Create(sURL)
objStream = sResponse.GetResponse.GetResponseStream()

Please Please Answer me with java code stuck in this...

thank you
Posted

 
Share this answer
 
Comments
hareshdgr8 7-Dec-15 4:54am    
sir I refer that link but didn't work for me and first link is in php not in java I need in java please help me

and
sir other link is not helpfull
Richard MacCutchan 7-Dec-15 6:24am    
Then you will need to refine the search terms to meet your specific needs.
hareshdgr8 7-Dec-15 8:00am    
Not Usefull sorry sir :-(
Richard MacCutchan 7-Dec-15 12:32pm    
In what way not useful? Did you follow that link and read the description? Do you now understand why you get the response "OK" and nothing else? Do you know what other calls you need to make to get the full details from the HTML response?
In your code use the method below after changing your code as follow:


From
C#
System.out.println(uc.getResponseMessage());



To

C#
System.out.println(doHttpUrlConnectionAction(uc));














C#
/**
   * Returns the output from the given URL.
   * 
   * I tried to hide exception-handling in this method, and just return a high
   * level Exception from here.
   * Modify this behavior as desired.
   * 
   * @param connection
   * @return
   * @throws Exception
   */
  private String doHttpUrlConnectionAction(HttpURLConnection connection)
  throws Exception
  {
    BufferedReader reader = null;
    StringBuilder stringBuilder;
 
    try
    {
      connection.connect();
 
      // read the output from the server
      reader = new BufferedReader(new   
     InputStreamReader(connection.getInputStream()));
      stringBuilder = new StringBuilder();
 
      String line = null;
      while ((line = reader.readLine()) != null)
      {
        stringBuilder.append(line + "\n");
      }
      return stringBuilder.toString();
    }
    catch (Exception e)
    {
      e.printStackTrace();
      throw e;
    }
    finally
    {
      // close the reader; this can throw an exception too, so
      // wrap it in another try/catch block.
      if (reader != null)
      {
        try
        {
          reader.close();
        }
        catch (IOException ioe)
        {
          ioe.printStackTrace();
        }
      }
    }
  }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900