0
从this site,有一个我想要调用的HTTP请求。 (不完全相同的凭据和内容,但结构相同)它用于发送彩信。如何在PHP中调用HTTP多部分/相关请求?
POST [XXX] HTTP/1.1
Host: europe.ipx.com
Content-Type: multipart/related; type="text/xml"; boundary="----=_037e2e9a2f4e80683dd5c5ec875fb0ce"
Authorization: Basic [XXX]
Content-Length: 18800
Cache-Control: no-cache
Pragma: no-cache
Accept: text/html, image/gif, image/jpg, *; q=.2, */*; q=.2
Connection: keep-alive
------=_037e2e9a2f4e80683dd5c5ec875fb0ce
Content-Type: text/xml; charset=utf-8
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<mm7:TransactionID xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-2">[XXX]_20090605211315</mm7:TransactionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<mm7:SubmitReq xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-2">
<mm7:MM7Version>6.5.0</mm7:MM7Version>
<mm7:SenderIdentification>
<mm7:VASPID>[XXX]</mm7:VASPID>
<mm7:SenderAddress>
<mm7:ShortCode>[XXX]</mm7:ShortCode>
</mm7:SenderAddress>
</mm7:SenderIdentification>
<mm7:Recipients>
<mm7:To>
<mm7:Number>46733[XXX]</mm7:Number>
</mm7:To>
</mm7:Recipients>
<mm7:ServiceCode>[XXX]</mm7:ServiceCode>
<mm7:DeliveryReport>1</mm7:DeliveryReport>
<mm7:Subject>MMS Subject</mm7:Subject>
<mm7:Content href="cid:attachment_1"/>
</mm7:SubmitReq>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
------=_037e2e9a2f4e80683dd5c5ec875fb0ce
Content-Type: application/vnd.wap.multipart.related; boundary="----=_45435153f79e2b654ebf607c4d65e15e"
Content-Id: <attachment_1>
------=_45435153f79e2b654ebf607c4d65e15e
Content-Type: application/smil
Content-ID: <smil_1.smil>
<smil>
<head>
<layout>
<root-layout background-color="#FFFFFF" height="240px" width="160px"/>
<region id="Image" top="0" left="0" height="50%" width="100%" fit="hidden"/>
<region id="Text" top="50%" left="0" height="50%" width="100%" fit="hidden"/>
</layout>
</head>
<body>
<par dur="12000ms">
<img src="pin_image.jpg" region="Image"></img>
<text src="text_1.txt" size="12" region="Text">
<param name="textsize" value="small" />
</text>
</par>
<par dur="8000ms">
<text src="text_2.txt" size="12" region="Text">
<param name="textsize" value="small" />
</text>
</par>
</body>
</smil>
------=_45435153f79e2b654ebf607c4d65e15e
Content-Type: text/plain; charset=utf-8; name=text_1.txt
Content-ID: <text_1.txt>
Hello!
This is the first text-block.
------=_45435153f79e2b654ebf607c4d65e15e
Content-Type: text/plain; charset=utf-8; name=text_2.txt
Content-ID: <text_2.txt>
And this is the second text-block.
------=_45435153f79e2b654ebf607c4d65e15e
Content-Type: image/jpg; name=pin_image.jpg
Content-Transfer-Encoding: base64
Content-ID: <pin_image.jpg>
/* base64-image stripped out from code due to its length */
------=_45435153f79e2b654ebf607c4d65e15e--
------=_037e2e9a2f4e80683dd5c5ec875fb0ce--Array
要发送请求,我在PHP中使用curl函数,但如果需要,我打开使用其他库。
问题是我在调用中看到多个Content-Type
,据我所知,我不能在curl_setopt
多次设置Content-Type
?但是,它似乎不是多个HTTP请求,因为Host
只出现一次。我如何在PHP中创建这样的HTTP请求?
在这个例子中,'headers'可能会设置Content-Type,以使它更清楚地回答OP,它回答了问题的这一部分。对? –
@DanielStenberg对。 – Finwe
我并不熟悉guzzle(但知道它是什么),但我敢打赌这个代码导致'multipart/form-data'请求,而不是'multipart/related'请求,不管那是 – hanshenrik