问题描述
我在将数据放入 Zoho 图书 API 时遇到错误请求 (400) 问题。 通过 POSTMAN,我以表单数据格式发送 JSON 数据并且它正在那里工作。 对于这个 PUT 请求邮递员控制台看起来像这样:
@H_502_3@PUT https://books.****.com/api/v3/items/2154170000005613003 200 693 ms PUT /api/v3/items/2154170000005613003 HTTP/1.1 Authorization: Bearer 1000.80483ac80*****d74513ee10998f.d3eafa5346*****ce57d6089d7edb User-Agent: PostmanRuntime/7.26.8 Accept: */* Cache-Control: no-cache Postman-Token: 26bdbba3-c2d7-4c99-a1aa-d0f539ec3865 Host: books.marbletrend.com Accept-Encoding: gzip,deflate,br Connection: keep-alive Content-Type: multipart/form-data; boundary=--------------------------889612260197335031082343 Content-Length: 238 ----------------------------889612260197335031082343 Content-disposition: form-data; name="JSONString" {"brand":"Neoliths","custom_fields":[{"label":"Lot #","value":"LottT"}]} ----------------------------889612260197335031082343--
当我使用 c# 发送请求时,出现错误:“远程服务器返回错误:(400) 错误请求。” 代码:
私有字节[] GetMultipartFormData(Dictionary
@H_502_3@ Encoding encoding = Encoding.UTF8; Stream formDataStream = new System.IO.MemoryStream(); //bool needsCLRF = false; foreach (var param in postParameters) { string postData = string.Format("{0}\r\nContent-disposition: form-data; name=\"{1}\"\r\n\r\n{2}\r\n\r\n--{3}--\r\n",formDataBoundary,param.Key,param.Value,formDataBoundary); formDataStream.Write(encoding.GetBytes(postData),encoding.GetByteCount(postData)); } //string footer = "\r\n--" + formDataBoundary + "--\r\n"; //formDataStream.Write(encoding.GetBytes(footer),encoding.GetByteCount(footer)); // Dump the Stream into a byte[] formDataStream.Position = 0; byte[] formData = new byte[formDataStream.Length]; formDataStream.Read(formData,formData.Length); formDataStream.Close(); return formData; }
这里是 postData 的值:
@H_502_3@------------053e811dac684623926086cc6c2c7ee5 Content-disposition: form-data; name="JSONString" {"brand":"Neoliths","value":"LottT"}]} --------------053e811dac684623926086cc6c2c7ee5--
This is the details of the request i.e sent through c# code
谁能告诉我需要在请求中更改什么才能成功 PUT 数据?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)