bradley525
asked on
json POST
Hello, below is a sample code of data I am trying to post and receive a response. I would like to do this in PHP but I am not sure how to? If not jQuery would be fine. Any help would be greatly appreciated..Not sure where to start..
POST https://securegateplus.nmp.neuroticmedia.net/Customer/Register HTTP/1.1
api-key: B6FFF46B-9557-42F0-AB88-2FA53C098E84
User-Agent: Fiddler
Host: securegateplus.nmp.neuroticmedia.net
Content-Length: 462
Content-Type: application/json; charset=utf-8
{
"Customer":
{
"UserName":"testers@neuroticmedia.com"
}
}
Do you have the documentation that tells what to send to the API? If so, please post it here or post a link to it, thanks.
You'll only be able to do it with jQuery if the remote server supports JSONP (if not you could push it through a proxy), but as Ray says, without documentation we'll be guessing all day long.
As for PHP, you're probably best off looking a cURL.
We're gonna need more info
As for PHP, you're probably best off looking a cURL.
We're gonna need more info
ASKER
Here is the API..I am working off of page 10 right now..
ASKER
forgot to attach...Here it is...Thanks
Neurolinq-Plus-API-v1.1--1-.pdf
Neurolinq-Plus-API-v1.1--1-.pdf
Sorry, I just don't have time to read a 62-page API manual. Is there any kind of a "quickstart" guide or another way we could get to the SSCCE?
ASKER
Sorry .thanks for the help..But I am not asking you to read to 62 pages...I am just on page 10 trying to get the request on the bottom of page 10 to work..thanks
OK, that shrinks the footprint a bit. Look at page 1 of the PDF document. It describes a RESTful access method. That is what I would recommend. I'll look at it a little bit more. While I am doing that, please read this article:
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12239-Introduction-to-Application-Programming-Interfaces.html
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12239-Introduction-to-Application-Programming-Interfaces.html
It looks like you would want to make a cURL POST-method request to this URL:
https://securegateplus.nmp.neuroticmedia.net/Customer/Register
I can't test this, but it may help to get you started. You might also want to consider fsockopen() to communicate with the API.
https://securegateplus.nmp.neuroticmedia.net/Customer/Register
I can't test this, but it may help to get you started. You might also want to consider fsockopen() to communicate with the API.
<?php // RAY_curl_post_async.php
error_reporting(E_ALL);
// DEMONSTRATE HOW TO USE CURL POST TO START AN ASYNCHRONOUS PROCESS
function curl_post
( $url
, $header
, $post_string
, $timeout=2
, $error_report=FALSE
)
{
// PREPARE THE CURL CALL
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, $url );
curl_setopt( $curl, CURLOPT_HEADER, $header );
curl_setopt( $curl, CURLOPT_POST, TRUE );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $post_string );
curl_setopt( $curl, CURLOPT_TIMEOUT, $timeout );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE );
// EXECUTE THE CURL CALL
$htm = curl_exec($curl);
$err = curl_errno($curl);
$inf = curl_getinfo($curl);
// ON FAILURE
if (!$htm)
{
// PROCESS ERRORS HERE
if ($error_report)
{
echo "CURL FAIL: $url TIMEOUT=$timeout, CURL_ERRNO=$err";
echo "<pre>\n";
var_dump($inf);
echo "</pre>\n";
}
curl_close($curl);
return FALSE;
}
// ON SUCCESS
curl_close($curl);
return $htm;
}
// PREPARE THE JSON STRING
$jso = <<<EOD
{
"BillingAddress":
{
"AddressName":"Billing",
"City":"Newnan",
"PostalCode":"30076",
"Province":"GA",
"Street1":"487 Gibson Rd"
},
"Customer":
{
"AgreedTermsDate":"\/Date(1297110939057-0500)\/",
"CellPhone":"678-777-3454",
"DateOfBirth":"\/Date(200462400000-0400)\/",
"FirstName":"Tim",
"LastName":"Kohler",
"MerchantID":"28908a45-750c-4ac6-81e3-98d7a0c889b0",
"Password":"password",
"UserName":"testers@neuroticmedia.com"
}
}
EOD;
// PREPARE THE HEADERS
$hdr[] = 'api-key: B6FFF46B-9557-42F0-AB88-2FA53C098E84';
$hdr[] = 'User-Agent: Fiddler'; // NOT SURE IF THIS MATTERS
$hdr[] = 'Content-Length: ' . strlen($jso);
$hdr[] = 'Content-Type: application/json; charset=utf-8';
// MAKE THE CALL
$resp = curl_post('https://securegateplus.nmp.neuroticmedia.net/Customer/Register', $hdr, $jso, 3, TRUE);
var_dump($resp);
HTH, ~Ray
ASKER
Thank you, but the result says FAIL
CURL FAIL: https://securegateplus.nmp.neuroticmedia.net/Customer/Register TIMEOUT=3, CURL_ERRNO=52
array(22) {
["url"]=>
string(62) "https://securegateplus.nmp.neuroticmedia.net/Customer/Register"
["content_type"]=>
NULL
["http_code"]=>
int(0)
["header_size"]=>
int(0)
["request_size"]=>
int(624)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(0)
["redirect_count"]=>
int(0)
["total_time"]=>
float(0.123081)
["namelookup_time"]=>
float(0.002697)
["connect_time"]=>
float(0.019398)
["pretransfer_time"]=>
float(0.100394)
["size_upload"]=>
float(461)
["size_download"]=>
float(0)
["speed_download"]=>
float(0)
["speed_upload"]=>
float(3745)
["download_content_length"]=>
float(-1)
["upload_content_length"]=>
float(461)
["starttransfer_time"]=>
float(0.123016)
["redirect_time"]=>
float(0)
["certinfo"]=>
array(0) {
}
["redirect_url"]=>
string(0) ""
}
bool(false)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The other solutions were on track, but they did not work. The above solution is tested and works.
The fact that the other solutions were on track means you should have accepted them as assisted solutions - you only got to where you got to because of the Experts help, so it's only right that you acknolwedge that!!
Open in new window
Otherwise (and I'm not a PHP guy) but the idea should be the same as any other <form> POST.
Open in new window