简体   繁体   English

HTTP POST请求和XML文件出错

[英]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. 好的,我有一个REST API,可以使用具有multipart / form-data形式的HTTP POST Request上载数据。

I try to test and build request in Postman App / Curl. 我尝试在Postman App / Curl中测试和构建请求。 When I attach xml file through app, all's ok — I've got 200 code and valid response. 当我通过应用程序附加xml文件时,一切正常—我有200条代码和有效的响应。

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. 但是,当我用原始查询建立相同的请求时,我从服务器收到500错误,看来它无法从请求中读取文件。

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. PS不用担心«Host»标头,我使用stunnel守护程序,因此我的数据通过TLS传输。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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