简体   繁体   中英

Problems processing HTTP POST

I've worked with PHP for many years and have setup many HTML forms which are then processed by another php page to insert a record into a database setting the POST parameters into individual fields.

I'm now working with a new webservice that is POSTing data to one of our PHP pages and we've been unable to parse out the POST parameters. I setup a test html form to mimic the POST and that works successfully.

I've been going through the IIS logs (Server is Windows Server 2008 R2 Standard Edition running IIS 7.5 and PHP 5.3.8) and have installed Microsoft Network Monitor to capture details about the POST data. Here's an excerpt showing the payload details for the Webservice and my HTML form:

Webservice: - client in IIS Log appears as: Apache-HttpClient/4.0.1+(java+1.5)

  • payload: HttpContentType = NetmonNull HTTPPayloadLine: inReplyToId=MG1133&to=61477751386&body=Test&from=61477751386&messageId=166652576&rateCode=

My HTML Form:

  • payload: HttpContentType = application/x-www-form-urlencoded inReplyToId: MG1133 to: 61477751386 body: Test from: 61477751386 messageId: 166594397

In the PHP page we're using a series of:

if(isset($_POST['inReplyToId']) && $_POST['inReplyToId'] !== '' ) {
    $request->setField('ReplyToID', $_POST['inReplyToId']);
    }

to grab the POST values and set them into fields as part of creating the new record in the database. When the Webservice does a POST none of the POST values are being set into the fields - the record is created but with empty field values.

When we perform complete the html form everything comes through as expected.

I'm not sure where to go next with troubleshooting this - I can see the different HttpContentType and the different structure to the payload but not sure whether this is the issue and what action I need to take.

Using file_get_contents('php://input') finally allowed me to see the POST data. I could then use parse_str() to generate variables from the string:

$postText = file_get_contents('php://input');
parse_str($postText);

if(isset($inReplyToId) && $inReplyToId !== '' ) {
$request->setField('_kf_GatewayMessageID', $inReplyToId);
}

and so on.

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