Answer the question
In order to leave comments, you need to log in
How to fix error sending XML file via HTTP POST request?
There is a REST API for uploading data to a third-party service (integration) via an HTTP POST request via the multipart/form-data form .
The general structure is three fields: login, password and attached data file .
When building and testing a request in the Postman application (or through the same Curl), everything is OK when the file is attached through the application interface. I get 200 code and a valid response.
But when I try to build the same request in a php application (or the same raw in Postman/Curl), I get a 500 error from the server, due to the fact that it cannot read the file from the http request.
Request example:
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
Answer the question
In order to leave comments, you need to log in
Thank you all, the problem turned out to be, firstly, the absence of additional "--" in the boundary, and secondly, that the line break in the application was converted from \r\n to \n
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question