我想将这些值存储到服务器。 我必须存储的数据在变量中完成。 我应该
{"response":{"result":1,"Message":"Poll Entered Successfully."}}
来自服务器 但得到 -1
@Override
protected String doInBackground(String... params) {
String jsonString = null;
HttpURLConnection linkConnection = null;
try {
String squestion = question.getText().toString();
String shashtag = hashTag.getText().toString();
spolltime = polltime.getText().toString();
StringBuilder scat = new StringBuilder();
scat.append("");
scat.append(categoryid);
StringBuilder sid = new StringBuilder();
sid.append("");
sid.append(LoginPage.logid);
//int ipolltime = Integer.parseInt(spolltime);
String equestion = URLEncoder.encode(squestion,"UTF-8");
String ehashtag = URLEncoder.encode(shashtag,"UTF-8");
String ecategory = URLEncoder.encode(scat.toString(),"UTF-8");
String eA = URLEncoder.encode(OptionA.stext,"UTF-8");
String eB = URLEncoder.encode(OptionB.stext,"UTF-8");
String eC = URLEncoder.encode(OptionC.stext,"UTF-8");
String eD = URLEncoder.encode(OptionD.stext,"UTF-8");
String eid = URLEncoder.encode(sid.toString(),"UTF-8");
String epolltime = URLEncoder.encode(spolltime,"UTF-8");
URL linkurl = new URL("http://iipacademy.in/askpoll/pollfeeds.php?user_id="+eid+"&question="+equestion+
"&hashtag="+ehashtag+"&category_id="+ecategory+"&option1="+eA+"&option2="+eB+"&option3="+eC+"&option4="+eD+"" +
"&pollopen="+epolltime+"&optiontype1=texty&optiontype2=texty&optiontype3=texty&optiontype4=texty");
linkConnection = (HttpURLConnection) linkurl.openConnection();
int responseCode = linkConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream linkinStream = linkConnection.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int j = 0;
while ((j = linkinStream.read()) != -1) {
baos.write(j);
}
byte[] data = baos.toByteArray();
jsonString = new String(data);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (linkConnection != null) {
linkConnection.disconnect();
}
}
//Toast.makeText(getApplicationContext(),jsonString.toString(),
//Toast.LENGTH_LONG).show();
return jsonString;
}
我无法找到我的错误!
感谢
答案 0 :(得分:0)
首先尝试从浏览器进行此调用并检查响应。有一个扩展 在Chrome PostMan休息客户端。请先检查一下。可能是你没有正确得到答复。