每次调用请求时都会出错。 当我用request.setPost(false)注释该行时,我从服务器得到一些响应。 请解释为什么会出现此错误。
线程中的异常"线程-6" java.lang.IllegalStateException:请求方法(post / get)无法修改一个参数
<pre>
<code>
public static void MyVimeo(final String file) {
new Thread(new Runnable() {
public void run() {
Log.p("File Name : " + file);
String consumer_key = "";
String consumer_secret = "";
String vimeoAPIURL = "http://vimeo.com/api/rest/v2";
String reqTokenEP = "http://vimeo.com/oauth/request_token";
String AUTHORIZATION_URL = "http://vimeo.com/oauth/authorize?oauth_token=";
String accTokenEP = "http://vimeo.com/oauth/access_token";
String accToken = "";
String accTokenPass = "";
NetworkManager networkManager = NetworkManager.getInstance();
networkManager.start();
networkManager.addErrorListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
NetworkEvent n = (NetworkEvent) evt;
n.getError().printStackTrace();
}
});
ConnectionRequest request = new ConnectionRequest() {
int chr;
StringBuffer sb = new StringBuffer();
String response = "";
protected void readResponse(InputStream input) throws IOException {
// do something with input stream
while ((chr = input.read()) != -1) {
sb.append((char) chr);
// System.out.println("reading...");
}
response = sb.toString();
Log.p("Response->" + response);
if (response.equals("OK")) {
Dialog.show("Response", "Authenticated", "Ok", null);
}
else {
Dialog.show("Response", "Failed", "Ok", null);
}
}
protected void handleException(Exception err) {
// do something with err
Dialog.show("Connection Err!!", "Are you connected to the internet? Check your connection", "Ok", null);
}
};
request.setUrl(vimeoAPIURL);
request.addArgument("format", "xml");
request.addArgument("method", "vimeo.videos.upload.getQuota");
request.addArgument("oauth_consumer_key", consumer_key);
request.addArgument("oauth_version","1.0");
request.addArgument("oauth_signature_method", "HMAC-SHA1");
request.addArgument("oauth_token", accToken);
Log.p("vimeoAPIURL->" + vimeoAPIURL + " called");
request.setPost(false); //error here
networkManager.addToQueue(request);
}
}).start();
}
</code>
</pre>
答案 0 :(得分:2)
setPost
。只需在所有addArgument调用之前调用它。实际错误是:
"Request method (post/get) can't be modified once arguments have been assigned to the request"
在当前版本中,有一个拼写错误,它表示一个而不是一次。