我想发送和对象(application / xml)为multipart-form。
;This is the capture of request in java what goes right: POST /OpenKM/services/rest/document/create HTTP/1.1 Accept: application/xml Content-Type: multipart/form-data; boundary=Boundary_1_1316797734_1423153602196 Authorization: Basic b2ttQWRtaW46YWRtaW4= MIME-Version: 1.0 User-Agent: Java/1.7.0_60 Host: localhost:8180 Connection: keep-alive Transfer-Encoding: chunked 74 --Boundary_1_1316797734_1423153602196 **Content-Type: application/xml Content-Disposition: form-data; name="doc"** 20c <?xml version="1.0" encoding="UTF-8" standalone="yes"?><document><path>/okm:root/myDoc.doc</path><permissions>0</permissions><subscribed>false</subscribed><checkedOut>false</checkedOut><convertibleToDxf>false</convertibleToDxf><convertibleToPdf>false</convertibleToPdf><convertibleToSwf>false</convertibleToSwf><description></description><locked>false</locked><signed>false</signed></document> --Boundary_1_1316797734_1423153602196 Content-Type: application/octet-stream Content-Disposition: form-data; name="content" This is what I get from .net POST /OpenKM/services/rest/document/create HTTP/1.1 Authorization: Basic b2ttQWRtaW46YWRtaW4= Accept: application/xml User-Agent: RestSharp/104.4.0.0 Host: localhost:8180 Content-Type: multipart/form-data; boundary=-----------------------------28947758029299 Content-Length: 24353 Accept-Encoding: gzip, deflate Connection: Keep-Alive -------------------------------28947758029299 **Content-Disposition: form-data; name="doc"** <?xml version="1.0" encoding="UTF-8" standalone="yes"?><document> <lastModified>01/01/0001 0:00:00</lastModified> <locked>false</locked> <checkedOut>false</checkedOut> <signed>false</signed> <convertibleToPdf>false</convertibleToPdf> <convertibleToSwf>false</convertibleToSwf> <convertibleToDxf>false</convertibleToDxf> <created>01/01/0001 0:00:00</created> <path>/okm:root/myDoc.doc</path> <permissions>0</permissions> <subscribed>false</subscribed> </document> -------------------------------28947758029299 Content-Disposition: form-data; name="content"; filename="myDoc.doc" Content-Type: application/octet-stream
似乎差异是我没有表明内容是application / xml( Content-Type:application / xml ?)
这是我的代码,任何建议都是好的
IRestRequest request = new RestRequest(uriHelper.DOCUMENT_CREATE, Method.POST);
request.RequestFormat = DataFormat.Xml;
Document testdoc = new Document();
testdoc.path = "/okm:root/myDoc.doc";
string doc = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + request.XmlSerializer.Serialize (testdoc).Replace("<Document>", "<document>").Replace("</Document>", "</document>");
request.AddParameter("doc", doc);
byte[] bytes = beanHelper.ReadToEnd(fileStream);
String fileName = Path.GetFileName(docPath);
request.AddFile("content", bytes, fileName);
RestClient client = getClient(url, user, password);
IRestResponse<Document> response = client.Execute<Document>(request);