Would a misconfiguration in cookies and/or postfields lead to this 500 internal server error when using wp_remote_post to post data within Wordpress?Using 'Copy as cURL' from Chrome in windows command lineREST API - works in chrome but curl did not workcURL in PHP - how to translate 'copy as curl' from Chrome into proper PHPphp cURL request using modified headerscURL Login with PHPHow to use Chrome's “Copy as cURL” for multipart/form-data post requests on WindowsPOST 500 (Internal Error) phpDrupal 7 -Netscaler -Cookiescurl: (35) SSL connect error, NSS error -5938WordPress Form Not Submitting to Database If Autocompleted
Why is k-means used for non normally distributed data?
Lumix G7: Raw photos only in 1920x1440, no higher res available
Tkinter Program to teach Arabic Part 2 - Proper use of Global Variables
Is torque as fundamental a concept as force?
Map a function that takes arguments in different levels of a list
How to annoymously report the Establishment Clause being broken?
How to use multiple criteria for -find
What is the significance of 104%?
Using font to highlight a god's speech in dialogue
What is the converted mana cost of land cards?
Field of a uniformly charged disk: integration question
Why not use futuristic pavise ballistic shields for protection?
Given a specific computer system, is it possible to estimate the actual precise run time of a piece of Assembly code
Is it rude to ask my opponent to resign an online game when they have a lost endgame?
Heuristic argument for the Riemann Hypothesis
How is total raw calculated for Science Pack 2?
Calculus Books, preferably Soviet.
Meaning of "offen balkon machen"?
Punishment in pacifist society
Does secure hashing imply secure symmetric encryption?
I have two helper functions that are the exact same, one executes and one doesn't. How come?
Do index funds really have double-digit percents annual return rates?
Tiny image scraper for xkcd.com
Does the Scrying spell require you to have a clear path to the target in order to work?
Would a misconfiguration in cookies and/or postfields lead to this 500 internal server error when using wp_remote_post to post data within Wordpress?
Using 'Copy as cURL' from Chrome in windows command lineREST API - works in chrome but curl did not workcURL in PHP - how to translate 'copy as curl' from Chrome into proper PHPphp cURL request using modified headerscURL Login with PHPHow to use Chrome's “Copy as cURL” for multipart/form-data post requests on WindowsPOST 500 (Internal Error) phpDrupal 7 -Netscaler -Cookiescurl: (35) SSL connect error, NSS error -5938WordPress Form Not Submitting to Database If Autocompleted
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am connecting to a server that does not have a published API and have successfully been able to use the PHP curl functions to retrieve a token and login, but when I try to use Wordpress built-in functions to achieve the same thing, I am not successful and receive a 500 Internal Server Error from the remote host. I believe that I may need to properly configure the cookies and/or data parameters.
I am able to retrieve a token from the remote host using wp_remote_get. I have tried changing the Content-Type to text, json and other common alternatives, although 'application/x-www-form-urlencoded' worked fine when using curl. I have tried sending the token in the header as well as in post fields.
// I am trying to get this to work:
$token = get_transient('access_token');
if (!$token)
return;
$args = array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'compress' => true,
'headers' => array(
'Authority' => 'remote.site.com',
'Content-Type' => 'application/x-www-form-urlencoded',
'Referer' => 'remote.site.com/login',
'Cache-Control' => 'max-age=0',
'Upgrade-Insecure-Requests' => 1,
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
'Accept-Encoding' => 'gzip, deflate, br',
'Accept-Language' => 'zh-CN,zh;q=0.9,en;q=0.8,ms;q=0.7,zh-TW;q=0.6,fr;q=0.5',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3'
),
'cookies' => array(),
'body' => array(
'__RequestVerificationToken' => $token,
'UserName' => USERNAME,
'Password' => PASSWORD,
'RememberMe' => true
)
);
$response = wp_remote_post( 'remote.site.com', $args);
// and no issue doing it this way...
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'remote.site.com/login');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "__RequestVerificationToken=$token&UserName=JohnDoe&Password=password&RememberMe=true");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Authority: remote.site.com';
$headers[] = 'Cache-Control: max-age=0';
$headers[] = 'Origin: https://remote.site.com';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8';
$headers[] = 'Referer: https://remote.site.com/login';
$headers[] = 'Accept-Encoding: gzip, deflate, br';
$headers[] = 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,ms;q=0.7,zh-TW;q=0.6,fr;q=0.5';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_HEADER, 1);
When using curl functions, I get 302 response for the login request and subsequent requests are fulfilled, whereas with wp_remote_post I get a response with the login page and a 500 internal server error response.
php wordpress rest curl
add a comment |
I am connecting to a server that does not have a published API and have successfully been able to use the PHP curl functions to retrieve a token and login, but when I try to use Wordpress built-in functions to achieve the same thing, I am not successful and receive a 500 Internal Server Error from the remote host. I believe that I may need to properly configure the cookies and/or data parameters.
I am able to retrieve a token from the remote host using wp_remote_get. I have tried changing the Content-Type to text, json and other common alternatives, although 'application/x-www-form-urlencoded' worked fine when using curl. I have tried sending the token in the header as well as in post fields.
// I am trying to get this to work:
$token = get_transient('access_token');
if (!$token)
return;
$args = array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'compress' => true,
'headers' => array(
'Authority' => 'remote.site.com',
'Content-Type' => 'application/x-www-form-urlencoded',
'Referer' => 'remote.site.com/login',
'Cache-Control' => 'max-age=0',
'Upgrade-Insecure-Requests' => 1,
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
'Accept-Encoding' => 'gzip, deflate, br',
'Accept-Language' => 'zh-CN,zh;q=0.9,en;q=0.8,ms;q=0.7,zh-TW;q=0.6,fr;q=0.5',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3'
),
'cookies' => array(),
'body' => array(
'__RequestVerificationToken' => $token,
'UserName' => USERNAME,
'Password' => PASSWORD,
'RememberMe' => true
)
);
$response = wp_remote_post( 'remote.site.com', $args);
// and no issue doing it this way...
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'remote.site.com/login');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "__RequestVerificationToken=$token&UserName=JohnDoe&Password=password&RememberMe=true");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Authority: remote.site.com';
$headers[] = 'Cache-Control: max-age=0';
$headers[] = 'Origin: https://remote.site.com';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8';
$headers[] = 'Referer: https://remote.site.com/login';
$headers[] = 'Accept-Encoding: gzip, deflate, br';
$headers[] = 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,ms;q=0.7,zh-TW;q=0.6,fr;q=0.5';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_HEADER, 1);
When using curl functions, I get 302 response for the login request and subsequent requests are fulfilled, whereas with wp_remote_post I get a response with the login page and a 500 internal server error response.
php wordpress rest curl
add a comment |
I am connecting to a server that does not have a published API and have successfully been able to use the PHP curl functions to retrieve a token and login, but when I try to use Wordpress built-in functions to achieve the same thing, I am not successful and receive a 500 Internal Server Error from the remote host. I believe that I may need to properly configure the cookies and/or data parameters.
I am able to retrieve a token from the remote host using wp_remote_get. I have tried changing the Content-Type to text, json and other common alternatives, although 'application/x-www-form-urlencoded' worked fine when using curl. I have tried sending the token in the header as well as in post fields.
// I am trying to get this to work:
$token = get_transient('access_token');
if (!$token)
return;
$args = array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'compress' => true,
'headers' => array(
'Authority' => 'remote.site.com',
'Content-Type' => 'application/x-www-form-urlencoded',
'Referer' => 'remote.site.com/login',
'Cache-Control' => 'max-age=0',
'Upgrade-Insecure-Requests' => 1,
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
'Accept-Encoding' => 'gzip, deflate, br',
'Accept-Language' => 'zh-CN,zh;q=0.9,en;q=0.8,ms;q=0.7,zh-TW;q=0.6,fr;q=0.5',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3'
),
'cookies' => array(),
'body' => array(
'__RequestVerificationToken' => $token,
'UserName' => USERNAME,
'Password' => PASSWORD,
'RememberMe' => true
)
);
$response = wp_remote_post( 'remote.site.com', $args);
// and no issue doing it this way...
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'remote.site.com/login');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "__RequestVerificationToken=$token&UserName=JohnDoe&Password=password&RememberMe=true");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Authority: remote.site.com';
$headers[] = 'Cache-Control: max-age=0';
$headers[] = 'Origin: https://remote.site.com';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8';
$headers[] = 'Referer: https://remote.site.com/login';
$headers[] = 'Accept-Encoding: gzip, deflate, br';
$headers[] = 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,ms;q=0.7,zh-TW;q=0.6,fr;q=0.5';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_HEADER, 1);
When using curl functions, I get 302 response for the login request and subsequent requests are fulfilled, whereas with wp_remote_post I get a response with the login page and a 500 internal server error response.
php wordpress rest curl
I am connecting to a server that does not have a published API and have successfully been able to use the PHP curl functions to retrieve a token and login, but when I try to use Wordpress built-in functions to achieve the same thing, I am not successful and receive a 500 Internal Server Error from the remote host. I believe that I may need to properly configure the cookies and/or data parameters.
I am able to retrieve a token from the remote host using wp_remote_get. I have tried changing the Content-Type to text, json and other common alternatives, although 'application/x-www-form-urlencoded' worked fine when using curl. I have tried sending the token in the header as well as in post fields.
// I am trying to get this to work:
$token = get_transient('access_token');
if (!$token)
return;
$args = array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'compress' => true,
'headers' => array(
'Authority' => 'remote.site.com',
'Content-Type' => 'application/x-www-form-urlencoded',
'Referer' => 'remote.site.com/login',
'Cache-Control' => 'max-age=0',
'Upgrade-Insecure-Requests' => 1,
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
'Accept-Encoding' => 'gzip, deflate, br',
'Accept-Language' => 'zh-CN,zh;q=0.9,en;q=0.8,ms;q=0.7,zh-TW;q=0.6,fr;q=0.5',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3'
),
'cookies' => array(),
'body' => array(
'__RequestVerificationToken' => $token,
'UserName' => USERNAME,
'Password' => PASSWORD,
'RememberMe' => true
)
);
$response = wp_remote_post( 'remote.site.com', $args);
// and no issue doing it this way...
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'remote.site.com/login');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "__RequestVerificationToken=$token&UserName=JohnDoe&Password=password&RememberMe=true");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Authority: remote.site.com';
$headers[] = 'Cache-Control: max-age=0';
$headers[] = 'Origin: https://remote.site.com';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8';
$headers[] = 'Referer: https://remote.site.com/login';
$headers[] = 'Accept-Encoding: gzip, deflate, br';
$headers[] = 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,ms;q=0.7,zh-TW;q=0.6,fr;q=0.5';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_HEADER, 1);
When using curl functions, I get 302 response for the login request and subsequent requests are fulfilled, whereas with wp_remote_post I get a response with the login page and a 500 internal server error response.
php wordpress rest curl
php wordpress rest curl
asked Mar 28 at 1:29
Michael NimriMichael Nimri
61 silver badge3 bronze badges
61 silver badge3 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
add code inside the wp-config file
define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] );
define( 'ADMIN_COOKIE_PATH', '/' );
define( 'COOKIEPATH', '/' );
define( 'SITECOOKIEPATH', '/' );
Yeah that didn't make a difference unfortunately.
– Michael Nimri
Mar 28 at 14:25
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55388886%2fwould-a-misconfiguration-in-cookies-and-or-postfields-lead-to-this-500-internal%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
add code inside the wp-config file
define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] );
define( 'ADMIN_COOKIE_PATH', '/' );
define( 'COOKIEPATH', '/' );
define( 'SITECOOKIEPATH', '/' );
Yeah that didn't make a difference unfortunately.
– Michael Nimri
Mar 28 at 14:25
add a comment |
add code inside the wp-config file
define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] );
define( 'ADMIN_COOKIE_PATH', '/' );
define( 'COOKIEPATH', '/' );
define( 'SITECOOKIEPATH', '/' );
Yeah that didn't make a difference unfortunately.
– Michael Nimri
Mar 28 at 14:25
add a comment |
add code inside the wp-config file
define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] );
define( 'ADMIN_COOKIE_PATH', '/' );
define( 'COOKIEPATH', '/' );
define( 'SITECOOKIEPATH', '/' );
add code inside the wp-config file
define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] );
define( 'ADMIN_COOKIE_PATH', '/' );
define( 'COOKIEPATH', '/' );
define( 'SITECOOKIEPATH', '/' );
answered Mar 28 at 11:24
MANOJ VASHISTMANOJ VASHIST
194 bronze badges
194 bronze badges
Yeah that didn't make a difference unfortunately.
– Michael Nimri
Mar 28 at 14:25
add a comment |
Yeah that didn't make a difference unfortunately.
– Michael Nimri
Mar 28 at 14:25
Yeah that didn't make a difference unfortunately.
– Michael Nimri
Mar 28 at 14:25
Yeah that didn't make a difference unfortunately.
– Michael Nimri
Mar 28 at 14:25
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55388886%2fwould-a-misconfiguration-in-cookies-and-or-postfields-lead-to-this-500-internal%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown