简体   繁体   中英

Error with HTTP POST Request and XML File

Ok, I have a REST API to upload data with HTTP POST Request with multipart/form-data form.

I try to test and build request in Postman App / Curl. When I attach xml file through app, all's ok — I've got 200 code and valid response.

But when I build the same request with raw body query I've got the 500 error from the server, seems it's cannot read a file from request.

POST /223/integration/integration/upload HTTP/1.1
Host: 127.0.0.1:223
Connection: Keep-Alive
Cache-Control: no-cache
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryp7MA4YWxkTrZu0gW

----WebKitFormBoundaryp7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="login"

mylogin
----WebKitFormBoundaryp7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="password"

mypassword
----WebKitFormBoundaryp7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="document"; filename="purchaseNotice.xml"
Content-Type: text/xml

<?xml version="1.0" encoding="UTF-8"?> <purchaseProtocolPAAE xmlns="http://zakupki.gov.ru/223fz/purchase/1" xmlns:t="http://zakupki.gov.ru/223fz/types/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://zakupki.gov.ru/223/integration/schema/TFF-2.0/purchase.xsd"> <t:header><t:guid>06adddd4-c7cc-4a5f-a667-7dd3f311bec9</t:guid><t:createDateTime>2013-12-19T16:43:51</t:createDateTime></t:header> <body><item><t:guid>a99d3960-2be6-4baf-aae6-69a4074bd0ec</t:guid><purchaseProtocolPAAEData><guid>e8274477-52e7-4088-9b47-96ae26e93280</guid><createDateTime>2013-12-19T14:49:38</createDateTime><purchaseInfo><t:purchaseNoticeNumber>12345678902</t:purchaseNoticeNumber></purchaseInfo><placer><t:mainInfo><t:inn>3905088712</t:inn><t:kpp>390601001</t:kpp><t:ogrn>1083905000080</t:ogrn></t:mainInfo></placer><customer><t:mainInfo><t:inn>3905088712</t:inn><t:kpp>390601001</t:kpp><t:ogrn>1083905000080</t:ogrn></t:mainInfo></customer><auctionStartDate>2013-12-19T16:40:00</auctionStartDate><auctionEndDate>2013-12-19T16:43:50</auctionEndDate><protocolRZ1Requisites><t:registrationNumber>12345678901-12</t:registrationNumber><t:version>1</t:version></protocolRZ1Requisites><lotApplicationsList><protocolLotApplications><lot><guid>9f36d9bd-3d87-4894-814a-87d295e9a542</guid><ordinalNumber>1</ordinalNumber><subject>Предмет нефтяного договора</subject><initialSumInfo>123.00 руб.</initialSumInfo></lot><lotParameters><nonPrice>0</nonPrice></lotParameters><application><applicationNumber>1</applicationNumber></application><application><applicationNumber>2</applicationNumber></application></protocolLotApplications></lotApplicationsList></purchaseProtocolPAAEData></item></body> </purchaseProtocolPAAE>
----WebKitFormBoundaryp7MA4YWxkTrZu0gW

So what's the problem with it?

PS Never mind about «Host» header, I use stunnel daemon, so my data transfers with TLS.

请求中存在两个问题:首先,请求在主体边界中缺少附加的“-”,其次是应用中的错误换行符从“ \\ r \\ n”转换为“ \\ n”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM