java webwervice
package com.mms;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class MMSDemo {
private String method="GetTaskList";
private Integer Customer_id = ;
private String Corp_Account = "";
private String Token = "";
public String createTask() throws IOException{
HttpURLConnection httpconn = null;
String result="-20";
StringBuffer sb = new StringBuffer();
sb.append("http://221.179.219.243:8080/eepwww/TaskServlet?Method=");
sb.append(method);
sb.append("&Customer_id=");
sb.append(6591);
sb.append("&Corp_Account=");
sb.append(Corp_Account);
sb.append("&Token=");
sb.append(Token);
sb.append("&START=");
sb.append(0);
sb.append("&END=");
sb.append(10);
try {
URL url = new URL(sb.toString());
httpconn = (HttpURLConnection) url.openConnection();
BufferedReader rd = new BufferedReader(new InputStreamReader(httpconn.getInputStream()));
result = rd.readLine();
rd.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
public static void main(String[] args) throws IOException {
MMSDemo mms = new MMSDemo();
String mms_str = mms.createTask();
System.out.println("mms:"+mms_str);
}
}
我这样对接一个彩信接口 它就回我一句话
mms:The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL). 这是怎回事
这是我对接接口的详细说明
那位大神来帮下忙 --------------------编程问答-------------------- 这个是对方的服务问题吗?
试试用POST看看?
setRequestMethod(String method)
Set the method for the URL request, one of: GET POST HEAD OPTIONS PUT DELETE TRACE are legal, subject to protocol restrictions.
--------------------编程问答-------------------- TaskServlet 这个没有doGet吧。 --------------------编程问答-------------------- 这是以dopost方式 提交的,不过我不太清楚应该怎样改成post方式啊 --------------------编程问答-------------------- 好像默认 HttpURLConnection 的method是GET
那在httpconn = (HttpURLConnection) url.openConnection();后面加一句
httpconn.setRequestMethod("POST");看看?
--------------------编程问答--------------------
嗯 是这样的 --------------------编程问答--------------------
我改成post就可以了 谢谢你们了 --------------------编程问答--------------------
嗯 谢谢
补充:Java , Java相关