I am trying to POST "/orders" to GDAX using a simple PHP function. I am getting no response and no errors. Orders are not getting placed and there are no PHP errors/warnings.
Not sure where I am going wrong.
function gdaxPost ($path, $post_array){
$url = 'https://api-public.sandbox.gdax.com/'.$path;
// Sandbox API #1 - fake key
$key = "03cc35bd4fb48ardad8097e0a45f";
$secret = "ihGzWV+li8AweKcL+oMDUvBzlmq9fR7z6rKksg43VFcWA3zysg6TxM+gGhEn0wg==";
$passphrase = "jqer9jxgfa6qcl";
$time = time();
$data = $time."POST"."/orders";
$sign = base64_encode(hash_hmac("sha256", $data, base64_decode($secret), true));
$headers = array(
'CB-ACCESS-KEY: '.$key,
'CB-ACCESS-SIGN: '.$sign,
'CB-ACCESS-TIMESTAMP: '.$time,
'CB-ACCESS-PASSPHRASE: '.$passphrase,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_array));
curl_setopt($ch, CURLOPT_URL, $url);
$res = curl_exec($ch);
return $res;
}
$path = 'orders';
$post_array = array(
"price" => "600",
"size" => "1.01",
"side" => "buy",
"type" => 'limit',
"time_in_force" => "GTC",
"product_id" => "BTC-USD"
);
print_r(json_decode(gdaxPost ($path, $post_array)),true);
EDIT: I fixed the code!
This is the updated working code:
function gdaxPost ($path, $post_array){
$url = 'https://api-public.sandbox.gdax.com/'.$path;
// Sandbox API #1 - fake key
$key = "03cc35bd4fb48ardad8097e0a45f";
$secret = "ihGzWV+li8AweKcL+oMDUvBzlmq9fR7z6rKksg43VFcWA3zysg6TxM+gGhEn0wg==";
$passphrase = "jqer9jxgfa6qcl";
$time = time();
$data = $time."POST"."/".$path.json_encode($post_array);
$sign = base64_encode(hash_hmac("sha256", $data, base64_decode($secret), true));
$headers = array(
'CB-ACCESS-KEY: '.$key,
'CB-ACCESS-SIGN: '.$sign,
'CB-ACCESS-TIMESTAMP: '.$time,
'CB-ACCESS-PASSPHRASE: '.$passphrase,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_array));
curl_setopt($ch, CURLOPT_URL, $url);
$res = curl_exec($ch);
return $res;
}
$path = 'orders';
$post_array = array(
"price" => "600",
"size" => "1.01",
"side" => "buy",
"type" => 'limit',
"time_in_force" => "GTC",
"product_id" => "BTC-USD"
);
print_r(gdaxPost ($path, $post_array));
Related
function getData()
{
$ch = curl_init();
$url = 'https://metrics.gameanalytics.com/metrics/v1/metrics/ad_impressions_per_user?';
$key = 'myapikeyhere';
$fields = array(
"granularity" => "day",
"interval" => "2022-10-21T04:00:00.000Z/2022-11-21T04:00:00.000Z",
"query" => array(
"dimension" => "ad_type",
"limit" => 3,
"type" => "group"
)
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Accept-Encoding: gzip, deflate',
'Connection: close',
'Host: metrics.gameanalytics.com',
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
"X-API-Key: $key",
)); //you can specify multiple custom keys.
$result = curl_exec($ch);
curl_close($ch);
print_r(json_decode($result));
}
` its my code i always getting (415 Unsupported Media Type). i need solution or some example
gameanalytics metric api using curl php.`
I'm working on Payfort API integration, and facing a problem with integrating using PHP. The link which I have followed mistake is in merchant reference. Where to get this reference?
<?php
$merchant_reference = 'TEST81003';
$redirectUrl = 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi';
$return_url = 'https://love.ae/admin/public/login';
$requestParams = array(
'command' => 'PURCHASE',
'access_code' => 'bSCrsxniHsJqWtQ9ki15',
'merchant_identifier' => 'xPzUtIjC',
'merchant_reference' => 'TEST81003',
'amount' => 1050*100,
'currency' => 'AED',
'language' => 'en',
'customer_email' => 'alraqbani#gmail.com',
'token_name' => 'ali',
'return_url' => 'https://love.ae/admin/public/login',
'card_security_code' => '123',
);
// calculating signature
$shaString = '';
ksort($requestParams);
$SHARequestPhrase = '$2y$10$IGSCjOlk9';
$SHAResponsePhrase = '$2y$10$Ll6DBCeeH';
$SHAType = 'sha256';
foreach ($requestParams as $k => $v) {
$shaString .= "$k=$v";
}
if (1 == 1)
$shaString = $SHARequestPhrase . $shaString . $SHARequestPhrase;
else
$shaString = $SHAResponsePhrase . $shaString . $SHAResponsePhrase;
$signature = hash($SHAType, $shaString);
$requestParams['signature'] = hash($SHAType, $shaString);
// calling payfort api using curl
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
$useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;charset=UTF-8',
//'Accept: application/json, application/*+json',
//'Connection:keep-alive'
));
curl_setopt($ch, CURLOPT_URL, $redirectUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); // The number of seconds to wait while trying to connect
//curl_setopt($ch, CURLOPT_TIMEOUT, Yii::app()->params['apiCallTimeout']); // timeout in seconds
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestParams));
$response = curl_exec($ch);
print_r($response);
curl_close($ch);
return $response;
?>
{"amount":"105000","response_code":"00044","signature":"e85cd4511c0b21649871c3b857d8782a1f4c326325cb04891720a2bb1bae400c","merchant_identifier":"xPzUtIjC","access_code":"bSCrsxniHsJqWtQ9ki15","language":"en","command":"PURCHASE","response_message":"Token name does not exist","merchant_reference":"TEST81003","customer_email":"alraqbani#gmail.com","currency":"AED","status":"00"}
<?php
$merchant_reference = 'TEST81003';
$redirectUrl = 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi';
$return_url = 'https://love.ae/admin/public/login';
$requestParams = array(
'command' => 'PURCHASE',
'access_code' => 'bSCrsxniHsJqWtQ9ki15',
'merchant_identifier' => 'xPzUtIjC',
'merchant_reference' => 'TEST81003',
'amount' => 1050*100,
'currency' => 'AED',
'language' => 'en',
'customer_email' => 'alraqbani#gmail.com',
'token_name' => 'ali',
'return_url' => 'https://love.ae/admin/public/login',
'card_security_code' => '123',
);
// calculating signature
$shaString = '';
ksort($requestParams);
$SHARequestPhrase = '$2y$10$IGSCjOlk9';
$SHAResponsePhrase = '$2y$10$Ll6DBCeeH';
$SHAType = 'sha256';
foreach ($requestParams as $k => $v) {
$shaString .= "$k=$v";
}
if (1 == 1)
$shaString = $SHARequestPhrase . $shaString . $SHARequestPhrase;
else
$shaString = $SHAResponsePhrase . $shaString . $SHAResponsePhrase;
$signature = hash($SHAType, $shaString);
$requestParams['signature'] = hash($SHAType, $shaString);
// calling payfort api using curl
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
$useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101
Firefox/20.0";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;charset=UTF-8',
//'Accept: application/json, application/*+json',
//'Connection:keep-alive'
));
curl_setopt($ch, CURLOPT_URL, $redirectUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); // The number of seconds to
wait while trying to connect
//curl_setopt($ch, CURLOPT_TIMEOUT, Yii::app()->params['apiCallTimeout']);
// timeout in seconds
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestParams));
$response = curl_exec($ch);
print_r($response);
curl_close($ch);
return $response;
?>
merchant_reference is a unique order number for each payment request.
It could be Primary key of the table or can be generated uniquely.
e.g.
$merchant_reference = '5000-'.time();
merchant_reference
Alphanumeric
Max: 40
I need to send POST data via cURL as shown in the picture.
image with POST data
i have this code
$data = [
'action' => 'order_cost',
'address' => 'http://91.211.117.3:720'
];
$query = http_build_query($data);
$url = "https://ap4.taxi/api/TaxiAPI.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryvJFySHvqeKppEN9W',
)
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
$output = curl_exec($ch);
curl_close($ch);
var_dump($output);
but I get an error
image with error
I have already tried many options. Postman sends POST normally and I receive the answer.
Please tell me I can not even imagine how this can be done.
As I see from your code you are sending just two fields by POST method (action and address)
Please show us a code of https://ap4.taxi/api/TaxiAPI.php where you process received data.
function execute_curl($url, $curlopt = array()){
$ch = curl_init();
$strCookie = session_name().'='.session_id().'; path=/';
session_write_close();
$default_curlopt = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_COOKIE => $strCookie,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 AlexaToolbar/alxf-1.54 Firefox/3.6.13 GTB7.1"
);
$curlopt = $curlopt + $default_curlopt;
curl_setopt_array($ch, $curlopt);
$response = curl_exec($ch);
$errormsg = curl_error($ch);
$errorCode = curl_errno($ch);
$results = array();
if($errormsg)
{
$results['status'] = 'error';
$results['data'] = $errormsg;
$results['errorcodetxt'] = curl_error_codes($errorCode);
}
else
{
$results['status'] = 'success';
$results['data'] = $response;
}
curl_close($ch);
return $results;
}
$curlopt = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => 1);
$curlresponse = execute_curl($url, $curlopt);
I am wondering how do I make this code support arrays?
i'am trying to send parameters via php curl in a stock screener to have the result in this page:
https://finance.yahoo.com/screener/unsaved/f0171a68-053e-42f2-a941-d6ecdf2ba6d1?offset=25&count=25
parameters
here is my php code
<?php
$url = 'https://query1.finance.yahoo.com/v1/finance/screener?lang=en-US®ion=US&formatted=true&corsDomain=finance.yahoo.com';
// $url = 'https://finance.yahoo.com/screener/unsaved/f0171a68-053e-42f2-a941-d6ecdf2ba6d1';
$parameters =
[
'size' => 25,
'offset' => 50,
'sortField' => 'intradaymarketcap',
'sortType' => 'DESC',
'quoteType' => 'EQUITY',
'topOperator' => 'AND',
'query' => array(
'operator' => 'AND',
'operands'=> array(
'operator' => 'or',
'operands' => array(
'operator' => 'EQ',
'operands' => array("region","jp")
)
)
),
'userId' => 'HFEELK3VBE3KPE4MGEA6PZTXXL',
'userIdType' => 'guid'
];
$parameters = json_encode($parameters);
$headers =
[
'Accept: application/json, text/javascript, */*; q=0.01',
'Accept-Language: en-US,en;q=0.5',
'X-Requested-With: XMLHttpRequest',
'Connection: keep-alive',
'Pragma: no-cache',
'Cache-Control: no-cache',
];
$cookie = tmpfile();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.31');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parameters));
// curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
?>
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parameters));
Change this line. If your problem is that you can send the body through curl then probably you need to send it as a json so try
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($parameters,true));
I saw your comment that you tried to send it already as array and i assume it did not work so i am almost sure that in your post you need to send a json (which is the most common body format for post requests)
Working Example
$data=array();
$data['amount']=100;
$data['to']='test';
$json=json_encode($data);
$header = array('Content-Type: application/json');
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($handle, CURLOPT_POSTFIELDS, $json);
curl_setopt($handle, CURLOPT_HTTPHEADER, $header);
$response=curl_exec($handle);
thank you pr1nc3 and Gurpal singh
i changed this line
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parameters));
for this one
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($parameters,true));
but i always have this result
'{"error":{"result":null,"error":{"code":"internal-error","description":"STREAMED"}}}'
here again the code
<?php
$url = 'https://query1.finance.yahoo.com/v1/finance/screener?lang=en-US®ion=US&formatted=true&corsDomain=finance.yahoo.com';
// $url = 'https://finance.yahoo.com/screener/unsaved/f0171a68-053e-42f2-a941-d6ecdf2ba6d1';
$parameters =
[
'size' => 25,
'offset' => 50,
'sortField' => 'intradaymarketcap',
'sortType' => 'DESC',
'quoteType' => 'EQUITY',
'topOperator' => 'AND',
'query' => array(
'operator' => 'AND',
'operands'=> array(
'operator' => 'or',
'operands' => array(
'operator' => 'EQ',
'operands' => array("region","jp")
)
)
),
'userId' => 'HFEELK3VBE3KPE4MGEA6PZTXXL',
'userIdType' => 'guid'
];
$headers =
[
'Accept: application/json, text/javascript, */*; q=0.01',
'Accept-Language: en-US,en;q=0.5',
'X-Requested-With: XMLHttpRequest',
'Connection: keep-alive',
'Pragma: no-cache',
'Cache-Control: no-cache',
];
$cookie = tmpfile();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.31');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($parameters,true));
// curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parameters));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
?>
i think the error is in the variable $parameters but i don't see where
when i compare view source send
{"size":25,"offset":0,"sortField":"intradaymarketcap","sortType":"DESC","quoteType":"EQUITY","topOperator":"AND","query":{"operator":"AND","operands":[{"operator":"or","operands":[{"operator":"EQ","operands":["region","jp"]}]}]},"userId":"HFEELK3VBE3KPE4MGEA6PZTXXL","userIdType":"guid"}
with my variable $parameters, there are diferences
{"size":25,"offset":0,"sortField":"intradaymarketcap","sortType":"DESC","quoteType":"EQUITY","topOperator":"AND","query":{"operator":"AND","operands":{"operator":"or","operands":{"operator":"EQ","operands":["region","jp"]}}},"userId":"HFEELK3VBE3KPE4MGEA6PZTXXL","userIdType":"guid"}
I'm quite new in PHP but for practise I wanted to write a script using curl for logging and send post request to a page site written in asp. I've used libcurl and simple_html_dom.php libraries.
Sometimes I got an error for invalid viewstate, this is the stack trace:
[ViewStateException: Invalid viewstate.
Client IP: 111.11.11.111
Port: 4743
User-Agent: Mozilla/5.0
ViewState: /wEPDwUKLTk1OTAzODYwMA9kFgJmD2QWBAIBD2QWAgIBD2QWCmYPFgIeBFRleHQFRTxtZXRhIHByb3BlcnR5PSJvZzp0aXRsZSIgY29udGVudD0iQURJREFTIEVRVCBSVU5OSU5HIENVU0hJT04gOTEiIC8+IGQCAQ8WAh8ABWY8bWV0YSBwcm9wZXJ0eT0ib2c6aW1hZ2UiIGNvbnRlbnQ9Imh0dHA6Ly9zaG9wLnVyYmFuanVuZ2xlc3RvcmUuaXQvZm90b19hcnRpY29saS9kNjc1NjgtaW50cm8uanBnIiAvPiBkAgIPFgIfAAWVBDxtZXRhIHByb3BlcnR5PSJvZzpkZXNjcmlwdGlvbiIgY29udGVudD0iUmVjZW50ZW1lbnRlLCBvbHRyZSBhbGxlIG1pdGljaGUgU3RhbiBTbWl0aCwgc29ubyB0b3JuYXRlIGluIGF1Z2UgZGVpIHBlenppIGRlbGxhIHNlcmllIE9kZGl0eS4gTmVsIDIwMDUgYWRpZGFzIGhhIGxhbmNpYXRvIHVuYSBjb2xsZXppb25lIHNwZWNpYWxlIGRpIHJ1bm5lcnMgY29uIGFsY3VuaSBkZWkgY29sb3JpIHBpJnVncmF2ZTsgcGF6emkgY2hlIHNpIHBvc3Nhbm8gbWV0dGVyZSBzdSB1bmEgc25lYWtlci4gRSBtZW50cmUgcXVlc3RvIG1vZGVsbG8gZGkgYWRpZGFzIEVRVCBSdW5uaW5nIEN1c2hpb24gbm9uIGZhIHVmZmljaWFsbWVudGUgcGFydGUgZGVsIHJpdG9ybm8gZGVsbGEgY29sbGV6aW9uZSBPZGRpdHkgKG8gZm9yc2UgcyZpZ3JhdmU7PyksIGx...]
[HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
http://go.microsoft.com/fwlink/?LinkID=314055]
System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +153
System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState) +14
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +237
System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) +4
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +37
System.Web.UI.HiddenFieldPageStatePersister.Load() +207
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +199
System.Web.UI.Page.LoadAllState() +43
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
System.Web.UI.Page.ProcessRequest() +80
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.web_articolo_aspx.ProcessRequest(HttpContext context) +37
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Here is my code:
<?php
include('simple_html_dom.php');
//method for logging
function login($url,$data){
$headers = array(
'Host' => 'site',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language' => 'en-US;q=0.5,en;q=0.3',
'Accept-Encoding' => 'gzip, deflate',
'Referer' => 'http://somesite.com',
'Connection' => 'keep-alive',
'Content-Type' => 'application/x-www-form-urlencoded'
);
$login = curl_init();
curl_setopt($login, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/cookie.txt");
curl_setopt($login, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/cookie.txt");
curl_setopt($login, CURLOPT_TIMEOUT, 4000);
curl_setopt($login, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($login, CURLOPT_URL, $url);
curl_setopt($login, CURLOPT_HEADER, 1);
curl_setopt($login, CURLOPT_HTTPHEADER, $headers);
curl_setopt($login, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0');
curl_setopt($login, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($login, CURLOPT_POST, 1);
curl_setopt($login, CURLOPT_POSTFIELDS, $data);
//$verbose = curl_setopt($login, CURLOPT_VERBOSE, true);
$ris = curl_exec ($login);
curl_close($login);
unset($login);
return $ris;
}
//method for posting data
function post_data($site,$data){
$datapost = curl_init();
curl_setopt($datapost, CURLOPT_URL, $site);
curl_setopt($datapost, CURLOPT_TIMEOUT, 4000);
curl_setopt($datapost, CURLOPT_HEADER, 1);
//curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers);
curl_setopt($datapost, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0');
curl_setopt($datapost, CURLOPT_POST, 1);
curl_setopt($datapost, CURLOPT_POSTFIELDS, $data);
curl_setopt($datapost, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/cookie.txt");
$result = curl_exec ($datapost);
curl_close ($datapost);
return $result;
}
function getParamLogin($url,$pageType) {
//return the html page
$html = file_get_html($url);
$eventtarget = '';
$eventargument = '';
if(sizeof($html->find('[id=__EVENTTARGET]')) > 0)
$eventtarget = $html->find('[id=__EVENTTARGET]')[0]->value;
if(sizeof($html->find('[id=__EVENTARGUMENT]')) > 0)
$eventargument = $html->find('[id=__EVENTARGUMENT]')[0]->value;
//post params
$params = array('ctl00_ScriptManager1_HiddenField' => $html->find('[id=ctl00_ScriptManager1_HiddenField]')[0]->value,
'__EVENTTARGET' => $eventtarget,
'__EVENTARGUMENT' => $eventargument,
'__VIEWSTATE' => $html->find('[id=__VIEWSTATE]')[0]->value,
'__VIEWSTATEGENERATOR' => $html->find('[id=__VIEWSTATEGENERATOR]')[0]->value,
'__EVENTVALIDATION' => $html->find('[id=__EVENTVALIDATION]')[0]->value,
'ctl00$search' => '',
'ctl00$newsletter' => ''
);
switch ($pageType) {
case 'firstpage':
$login = array('ctl00$pagina$tlogin_area' => 'user',
'ctl00$pagina$tpassword_area' => 'passwd',
'ctl00$pagina$tinvia' => 'ACCEDI',);
$params = array_merge($params,$login);
break;
case 'secondpage':
$cart = array('__SCROLLPOSITIONX' => '0',
'__SCROLLPOSITIONY' => '0',
'ctl00$pagina$taglie' => '6M',
'ctl00$pagina$tag' => 'Aggiungi al carrello');
$params = array_merge($params,$cart);
break;
}
print_r($params);
return $params;
}
?>
<?php
login('http://www.loginpage.com', getParamLogin('http://www.loginpage.com','firstpage'));
post_data('http://www.anotherpage.com',getParamLogin('http://www.anotherpage.com','secondpage'));
?>
I wonder if there is also a cookie in handle the cookie and then in the viewstate... Someone can help me? Thank you!