-1
私のポストサービスでキー値ペアを使用しています。私は「無効なパラメータ」として応答を得ています。私は同じ種類の記事を「application/x-www-form-urlencoded」というコンテンツタイプを使って投稿してみましたが、うまくいき、期待どおりのレスポンスを得ました。私は以下?何をしないのです、私はアンドロイドのキー値ペアを使用してポストサービスを使用しているときに無効なパラメータエラーが発生しました
private String invokeWebservice() {
String data = null;
HttpURLConnection conn = null;
BufferedReader in = null;
try {
String webservice = Constants.BASE_URL + serviceName;
URL url = new URL(webservice);
conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setUseCaches(false);
if (isPost) {
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setDoOutput(true);
Writer writer = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8"));
if (jsonObject != null)
writer.write(jsonObject.toString());
else {
writer.write(getPostDataString(keyValue));
}
writer.close();
}
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.separator");
while ((l = in.readLine()) != null)
sb.append(l + nl);
in.close();
data = sb.toString();
return data;
} catch (Exception e) {
Log.e("test", e.getMessage());
} finally {
try {
if (conn != null)
conn.disconnect();
if (in != null)
in.close();
} catch (Exception ex) {
}
}
return data;
}
を使用していたコードであり、私はあなたがこのアプローチを使用してくださいリクエストにパラメータを追加しないURLに
private String getPostDataString(HashMap<String, String> params) throws UnsupportedEncodingException {
StringBuilder postData = new StringBuilder();
for (Map.Entry<String, String> entry : params.entrySet()) {
if (postData.length() != 0)
postData.append('&');
postData.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
postData.append('=');
postData.append(URLEncoder.encode(String.valueOf(entry.getValue()), "UTF-8"));
}
return postData.toString();
}
それを使用してください作る名前とそれが@Abdul Waheedを動作していないなら、私に知らせましょう –