Batch (multipart) HTTP POST for Solve360 API

agolangf · · 1009 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;ve been pulling my hair out over this one for some time now. Using http.request I have everything working nicely when I only want to send a single request at a time...</p> <p>But Solve360 allows for batch requests.</p> <p>I would love to take advantage of this but I can&#39;t figure out how the heck to do it. I tried going down a path of attempting to embed an http.request within the body of another http.request, but that was entirely fruitless.</p> <p>Working with support I at least have a clear answer in terms of what the raw HTTP data needs to look like, here&#39;s the example:</p> <pre><code>POST /batch HTTP/1.1 Host: secure.solve360.com User-Agent: Go-http-client/1.1 Content-Length: 279 Authorization: Basic [redacted] Content-Type: multipart/mixed; boundary=THISISATESTBOUNDARY Accept-Encoding: gzip ------THISISATESTBOUNDARY POST /contacts HTTP/1.1 Host: secure.solve360.com User-Agent: Go-http-client/1.1 Content-Length: 92 Accept: application/json Content-Type: application/json Accept-Encoding: gzip {&#34;firstname&#34;:&#34;demoFirst&#34;,&#34;lastname&#34;:&#34;demoLast&#34;,&#34;categories&#34;:{&#34;add&#34;:{&#34;category&#34;:&#34;12220159&#34;}}} ------THISISATESTBOUNDARY </code></pre> <p>Notice the first portion that POSTs to /batch includes basic authentication, Content-Type: multipart/mixed, and a boundary is defined.</p> <p>In the second portion, <strong>POST /contacts</strong> tells the API I&#39;m dealing with creating a new contact record, there is no authentication in this portion, and notice <strong>Content-Type</strong> and <strong>Accept</strong> are both set to <strong>application/json</strong> which is different from the first portion. (I don&#39;t even know if this is important info but trying to be detailed :D)</p> <p>Also note that each portion has a <strong>Content-Length</strong> value that must be included.</p> <p>The last line before the final boundary is the JSON payload that includes the form field data for the new contact being created.</p> <p>Finally, boundary at the end.</p> <p>Is this API just too non-standard for it to work with http.request and/or the mime/multipart stuff included in Go packages?</p> <p>Here&#39;s the batch request documentation. Note: while it doesn&#39;t state that they accept JSON for batch requests, THEY DO. But, they also accept form data and xml... I really prefer JSON but am I making my life difficult by not using form encoded data to accomplish this? Link: <a href="https://solve360.com/api/batching-requests/" rel="nofollow">https://solve360.com/api/batching-requests/</a></p> <p>If someone could even roughly lead me in the direction I should be looking, that would be fantastic. Right now, I&#39;m not even sure I can salvage functionality using http.request and using stuff from mime/multipart package. Should I keep looking there, or is it fruitless given the format requirements?</p> <p>Thanks in advance for any help!!!</p>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1009 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传