I'm trying to send a POST request to a website with a cookie. As simple as that PHP makes it complicated and I have no clue what to do.
This below doesn't send the cookie as I want it to.
$ch = curl_init("https://auth.roblox.com/v2/logout");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array()));
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_COOKIE, ".ROBLOSECURITY=" . $cookie);
$resp = curl_exec($ch);
print_r ($resp);
I am trying to convert this python code into PHP; (this works)
jar = r.cookies.RequestsCookieJar()
jar.set('.ROBLOSECURITY', cookie, domain='.roblox.com', path='/')
resp = r.post(url="https://auth.roblox.com/v2/logout", cookies=jar)
output headers:
HTTP/1.1 401 Unauthorized
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 83
Content-Type: application/json
Expires: -1
X-Frame-Options: SAMEORIGIN
Roblox-Machine-Id: RP-WEB350
P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM
PRE"
Date: Sat, 27 Oct 2018 13:24:09 GMT
output body:
{"errors":[{"code":0,"message":"Authorization has been denied for this
request."}]}
Related
Having trouble transforming this python code into PHP, it doesn't seem like the PHP version sends the cookie.
Python:
jar = r.cookies.RequestsCookieJar()
jar.set('.ROBLOSECURITY', cookie, domain='.roblox.com', path='/')
resp = r.post(url="https://auth.roblox.com/v2/logout", cookies=jar)
print (resp.content)
My attempt at making it PHP:
$ch = curl_init("https://auth.roblox.com/v2/logout");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array()));
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_COOKIE, ".ROBLOSECURITY=" . $cookie);
$resp = curl_exec($ch);
print_r ($resp);
PHP Output:
HTTP/1.1 401 Unauthorized
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 83
Content-Type: application/json
Expires: -1
X-Frame-Options: SAMEORIGIN
Roblox-Machine-Id: RP-WEB1004
P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM
PRE"
Date: Sat, 27 Oct 2018 14:29:39 GMT
{"errors":[{"code":0,"message":"Authorization has been denied for this
request."}]}
iam using PHP CURL to send POSTFIELD but i Getting Error 415 Unsupported Media Type
Here it's my code :
$data = '<?xml version="1.0" encoding="euc-kr" ?>
<Product>
<selMnbdNckNm>Catenzo YI 099</selMnbdNckNm>
<selMthdCd>01</selMthdCd>
<dispCtgrNo></dispCtgrNo>
<prdAttrCd></prdAttrCd>
<dispCtgrNo></dispCtgrNo>
<prdAttrVal><prdAttrVal>
<prdNm></prdNm>
<prdStatCd></prdStatCd>
<prdWght></prdWght>
<dlvGrntYn></dlvGrntYn>
<minorSelCnYn></minorSelCnYn>
<suplDtyfrPrdClfCd></suplDtyfrPrdClfCd>
<prdImage01></prdImage01>
<prdImage02></prdImage02>
<prdImage03></prdImage03>
<prdImage04></prdImage04>
<prdImage05></prdImage05>
<htmlDetail></htmlDetail>
<selTermUseYn></selTermUseYn>
<selPrc></selPrc>
<prdSelQty></prdSelQty>
<asDetail></asDetail>
<rtngExchDetail></rtngExchDetail>
</Product>';
$data = simplexml_load_string($data);
$ch = curl_init();
$header = array(
"Content-Type: application/xml",
"Accept-Charset: utf-8",
"openapikey:myapikey",
'Content-Length: ' . strlen($data)
);
curl_setopt($ch, CURLOPT_URL, "http://dev.api.elevenia.co.id/rest/prodservices/product");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
//curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$return=curl_exec($ch);
echo "[MSG] Result -Xml : \n";
echo $return;
I getting error message
HTTP/1.1 415 Unsupported Media Type Date: Wed, 03 Jan 2018 18:19:00 GMT Server: Apache Cache-Control: no-cache Cache-Control: no-store Pragma: no-cache Content-Length: 903 Expires: Thu, 01 Jan 1970 00:00:00 GMT Set-Cookie: WMONID=RgWtbnOnqnT; expires=Thu, 03-Jan-2019 18:19:00 GMT; path=/ X-Powered-By: Servlet/2.5 JSP/2.1 Vary: User-Agent Content-Type: text/html; charset=UTF-8
I hope someone can help me.
Thank You for #astrangeloop and #frz3993 i just have small error with change $header to $headers, and the xml closing tag should be
I am trying to download a file with cURL. I have received an URL where the file is located, but the url makes an redirect before reaching the file. For some reason I always receive the logout page when I access the URL with cURL, but when I enter the URL directly in my browser the file just downloads as it is supposed to. The file that should be downloaded is a RAR file, but instead of the file I get the incorrect login page.
This the current code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
As you can see I am using the following code to allow the redirects:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
But I always receive the incorrect login page from the website if I use the above code. Can anyone see what I am doing wrong here ?
This is the reponse I get from the server:
HTTP/1.1 302 Found
Date: Tue, 26 Jan 2016 15:33:18 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.3.2
Set-Cookie: PHPSESSID=session_id; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: /nl/nl/export/download/t/Mg==/c/MTQ=/
Vary: Accept-Encoding
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Try with this code
$url = "www.abc.com/xyz";//your url will come here
$fp = fopen ('test.txt', 'w+');
$ch = curl_init(str_replace(" ","%20",$url));
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
I get an error every time when I'm trying to merge a pull request with the bitbucket api.
This is my code:
define('USERNAME','***');
define('PASSWORD','***');
$url = "https://bitbucket.org/api/2.0/repositories/{owner}/{repo}/pullrequests/46/merge";
$curl1 = curl_init();
curl_setopt($curl1, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt($curl1, CURLOPT_USERPWD, USERNAME . ":" . PASSWORD);
curl_setopt($curl1, CURLOPT_HEADER, true);
curl_setopt($curl1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl1, CURLOPT_URL, $url);
curl_setopt($curl1, CURLOPT_POST, true);
echo curl_exec($curl1);
And this is the error code:
HTTP/1.1 100 Continue HTTP/1.1 400 BAD REQUEST Server: nginx/1.6.2 Date: Wed, 20 May 2015 15:43:27 GMT Content-Type: application/json; charset=utf-8 Content-Length: 113 Connection: keep-alive X-Render-Time: 0.218739032745 Content-Language: de ETag: "2f0273bc2b819d7505bc14bf84d7e129" X-Request-Count: 227 X-Served-By: app19 Vary: Authorization, Accept-Language, Cookie X-Frame-Options: SAMEORIGIN X-Static-Version: 3b0c7aec39d3 X-Version: c288eef4a422 {"error": {"message": "'ascii' codec can't encode character u'\\xe4' in position 11: ordinal not in range(128)"}}
I've already tried to send the informations (owner, repo and request id) with "CURLOPT_POSTFIELDS". But I got the same error.
Can somebody help me?
I'm trying to work off the Harvest php API example from the GitHub page.
Here is the code, but there is no output no matter what I try to do. If I use the Chrome Postman app I can retrieve data. I'm not sure what I'm doing wrong. Confidential information was removed. Any help is much appreciated.
<?php
$url = "https://company.harvestapp.com/?daily=";
$temp = getURL($url);
echo $temp;
function getURL($url) {
$credentials = "<email>:<password>";
$headers = array(
"Content-Type: application/xml",
"Accept: application/xml",
"Authorization-Basic: " . base64_encode($credentials)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, "test app site");
$data = curl_exec($ch);
curl_close($ch);
if ($data !=false){
return $data;
}
else
return "no data";
}
?>
This is the error I get from the curl_error function:
HTTP/1.1 401 Unauthorized Server: nginx Date: Fri, 09 May 2014 22:59:27 GMT Content-Type: application/xml; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive Status: 401 Unauthorized Cache-Control: private, no-store, no-cache, max-age=0, must-revalidate X-Frame-Options: SAMEORIGIN X-Served-From: https://.harvestapp.com/ X-UA-Compatible: IE=Edge,chrome=1 Set-Cookie: _harvest_sess=; domain=.harvestapp.com; path=/; secure; HttpOnly X-Request-Id: e9d6eb74-5c73-430e-9854-ebf6f1c527c8 X-Runtime: 0.019223 You must be authenticated with Harvest to complete this request.