2016-02-25 36 views
-1

我嘗試在集成測試中的post請求中傳遞參數,但是我得到了需要檢測到參數「source」aint的響應。也許你會知道是什麼原因。謝謝。在集成測試中傳遞參數JAVA

public void testUploadBundleFromRepository() throws IOException, InterruptedException { 

    String boundary = "---------------"+ UUID.randomUUID().toString(); 

    String uri = String.format("http://%s:%d/upload/", HOST, PORT); 

    HttpPost httpPost = new HttpPost(uri); 
    httpPost.setHeader(HTTP.CONTENT_TYPE, ContentType.MULTIPART_FORM_DATA.getMimeType()+";boundary="+boundary); 

    List<NameValuePair> postParameters = new ArrayList<>(); 
    postParameters.add(new BasicNameValuePair("source","repo")); 
    postParameters.add(new BasicNameValuePair("id","1")); 
    postParameters.add(new BasicNameValuePair("start", "true")); 
    httpPost.setEntity(new UrlEncodedFormEntity(postParameters, "UTF-8")); 

    HttpResponse response = getHttpClient().execute(httpPost); 

    //assert in future 
} 

回答

0

我想你應該叫setRequestBody不setEntity

httpPost.setRequestBody(postParameters);