如何使用java调用SMS API [英] How to Call SMS API Using java

查看:123
本文介绍了如何使用java调用SMS API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是java代码,但我只得到回复OK

当我使用相同API的Vb.net时我得到了回应短信已成功发送





JAVA代码



String requestUrl =SOME API;



URL url =新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()



请回答我用java代码卡住这个...



谢谢

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

推荐答案

请参阅 https://www.google.com/search?q=java%20sms [ ^ ]。

在您的代码中使用以下方法更改您的代码如下:





来自

In your code use the method below after changing your code as follow:


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














To

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







< br $>


































/**
   * 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();
        }
      }
    }
  }


这篇关于如何使用java调用SMS API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆