<p>I'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'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'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
{"firstname":"demoFirst","lastname":"demoLast","categories":{"add":{"category":"12220159"}}}
------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'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'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's the batch request documentation. Note: while it doesn'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'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
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传