-3
中的POST請求,並在將JSON字符串發送到POST請求時遇到問題。如何將json字符串作爲輸入參數發送到android
這是我的網址:http://172.25.183.183:8080/JIRAservice/rest/runquery
鍵:查詢
值:
{ "jql": "project=<projectkey>",
"startAt": 0,
"maxResults": 100,
"fields": [
"summary",
"customfield_10006",
"status",
"description"
]
}
哪裏<projectkey>
是存儲在共享偏好的價值,請幫助
這是我的代碼
try{
TextView op=(TextView) findViewById(R.id.resp);
URL url=new URL("http://172.25.183.183:8080/JIRAservice/rest/runquery");
HttpsURLConnection conn=(HttpsURLConnection)url.openConnection();
conn.setRequestMethod("POST");
String projectKey=Home.savedid;
JSONObject jsonParam = new JSONObject();
jsonParam.put("query", " "{ \"jql\": \"project=" + projectKey + "\", \"startAt\": 0, \"maxResults\": 100, \"fields\": [\"summary\",\"customfield_10006\", \"status\", \"description\"] }"");
how to send the parameters??
conn.setDoOutput(true);
DataOutputStream dbstrm=new DataOutputStream(conn.getOutputStream());
dbstrm.flush();
dbstrm.close();
int respnse=conn.getResponseCode();
String output="Request URl"+url;
output+=System.getProperty("line.separator");
output+=System.getProperty("line.separator")+"Response Code"+respnse;
BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line= "";
StringBuilder respop=new StringBuilder();
while((line=br.readLine())!=null){
respop.append(line);
}
br.close();
output +=System.getProperty("line.separator")+respop.toString();
op.setText(output);
}catch(MalformedURLException ae){
ae.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
哪一部分的代碼,你已經? – devnull69
這很大程度上取決於服務器端的api ...您可以構建json對象並執行異步任務來發布您的數據......但是執行此操作的方法真的取決於您的服務器 –
關鍵和值應該同時發送 – Sireesha