0
我想有一個放置格式說明符(如%s)而不是放置硬編碼值的方法,您可以在下面找到我的代碼;string.format在http post請求和響應中拋出異常
String userName = "Nicole";
String password = "Nicole";
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("url");
String input=String.format("<soap:Envelope
xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:inn=\"http:Innovation/\">
<soap:Header/><soap:Body><inn:getCategoriesbyVendorID><!--Optional:-->
<userName>%s</userName><!--Optional:--><password>%s</password></inn:getCategoriesbyVendorID>
</soap:Body></soap:Envelope>",userName,password);
//StringEntity input = new StringEntity("<soap:Envelope
xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:inn=\"http:Innovation/\">
<soap:Header/><soap:Body><inn:getCategoriesbyVendorID><!--Optional:-->
<userName>Nicole</userName><!--Optional:--><password>Nicole</password>
</inn:getCategoriesbyVendorID></soap:Body></soap:Envelope>");
post.setEntity(input);
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new
InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
通過上面的代碼,Entity會引發錯誤。有人能幫我解決這個問題嗎?
什麼是異常(與堆棧跟蹤)? – PopoFibo
它在eclipse中顯示錯誤,即改變HTTP實體的輸入類型(post.set Entity(input);)。 – stanti