这是rest客户端的java代码。我在创建时遇到问题。如何在此客户端上创建 C# 等效项?我需要一些例子
public class RestServiceClient {
public static final String BASE_URL = "http://localhost:9080/PPAUploadDocRestService/rest/uploadDocument";
public static void main(String[] args) {
addDocument();
}
public static void addDocument() {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(BASE_URL);
MultipartEntity reqEntity = new MultipartEntity();
FileBody fileBody = new FileBody(new File("C:/projects/Db2PpaPpacardsppastages.xsd"));
reqEntity.addPart("file", fileBody);
reqEntity.addPart("fileName", new StringBody("Db2PpaPpacardsppastages.xsd"));
reqEntity.addPart("processId", new StringBody("2872"));
reqEntity.addPart("document", new StringBody(generateDocument()));
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
System.out.println(response.getStatusLine().getReasonPhrase());
} catch(Exception e) {
e.printStackTrace();
}
}
private static String generateDocument() {
JSONObject object = new JSONObject();
object.put("docNum", "NickDoc");
object.put("docDate", "" + new Date().getTime());
object.put("docTypeId", "49");
object.put("questionId", "1728");
object.put("description", "test by NIvanov REST");
object.put("resolution", "");
object.put("workGroupMembers", "");
object.put("inDocNum", "inNickDoc");
object.put("inDocDate", "" + new Date().getTime());
object.put("outDocNum", "outNickDoc");
object.put("outDocDate", "" + new Date().getTime());
object.put("docName", "NickDocName");
object.put("employeeId", "1");
object.put("cardId", "647");
object.put("bpmDocId", "");
object.put("docCode", "TNT");
return object.toString();
}
}
我一直在研究使用HttpWebRequest
andHttpWebResponse
对象。这是真的?