Actually it is more general question but now i am trying to use it on wordpress site so I preferred to post it here.

I am trying to understand the difference between remote post and form post.

When I query a string and post it to remote server, I get the result as string and with "print $response" see it on browser console. But I want it to be displayed as html on browser. Am I expecting wrong thing or could i do such thing?

Basically I want to see raw response as html.


In case of being more expressive.. I am trying to write credit card payment gateway inside woocommerce

Inside process_payment function which is called at the end of customer order, I am posting all info to bank server like below:

public function process_payment( $order_id ) {
    global $woocommerce;
    $okUrl = "http://localhost/xxx/wc-api/paymentpos/";         
    $failUrl = "http://localhost/xxx/wc-api/paymentpos/";
    $payload = array(.....);
         $response = wp_remote_post( $environment_url, array(
        'method'    => 'POST',
        'body'      => http_build_query( $payload ),
        'timeout'   => 45,
        'sslverify' => false,
    ) );
    $respbody = wp_remote_retrieve_body($response);
    print $respbody;

After that, bank server should reply to payment_callback() which is like

public function payment_callback(){

    global $woocommerce;

    wc_add_notice( 'OK', 'success' );

I am getting $respbody as below on console.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" language="javascript">
function moveWindow() {

<body onLoad="javascript:moveWindow()">
<form action="http://localhost/xxx/wc-api/paymentpos/" method="post" name="returnform">

 <input type="hidden" name="EXTRA.ERTELEMESABITTARIH" value="20121123">
 <input type="hidden" name="okUrl" value="http://localhost/xxx/wc-api/paymentpos/">
 <input type="hidden" name="mdStatus" value="2">

 <input type="hidden" name="HASH" value="QZVV9Zfv4tlzi36WJNbLVlbuWY8=">
 <input type="hidden" name="rnd" value="GSZV87rHM+Ol5WDiMbtC">
 <input type="hidden" name="HASHPARAMS" value="clientid:oid:AuthCode:ProcReturnCode:Response:mdStatus:cavv:eci:md:rnd:">
 <input type="hidden" name="HASHPARAMSVAL" value="100200000160451Declined2499850:FE7D7E1062435636DEA77FD3F96CE40C68334FAFE6458F2FC530F26814B29935:4043:##100200000GSZV87rHM+Ol5WDiMbtC">

    <!-- To support javascript unaware/disabled browsers -->
        Please Click to continue.<br>
        <input type="submit" name="submit" value="Submit" id="btnSbmt"></center>

This response should trigger payment_callback() function. Manually I could trigger payment_callback() like http://localhost/xxx/wc-api/paymentpos/. But this response could not trigger. I am suspicious about I could handle wp_remote_post response correctly.

  • Please show your code your using and what the expected output should be.
    – jgraup
    Nov 12, 2016 at 13:55
  • downvoted as it seems like the main issue here is understanding how payment transactions wrok, and how to debug them. both are not specific to wordpress Oct 20, 2017 at 17:59
  • Could you solve this problem? I have something similar the $respbody in test mode returns the parameters correctly, but in production mode it returns HTML code Dec 13, 2019 at 19:52

2 Answers 2


wp_remote_get returns a json string.

You have different function to work with this json response. wp_remote_head() wp_remote_retrieve_body(), wp_remote_retrieve_header(), wp_remote_retrieve_headers(), wp_remote_retrieve_response_code(), wp_remote_retrieve_response_message()

The example from the codex:

$response = wp_remote_get( 'http://www.example.com/index.html' );
  if( is_array($response) ) {
     $header = $response['headers']; // array of http header lines
     $body = $response['body']; // use the content

Depending on the page request, the body could be an array or object or HTML. Of course, in case of array or object, there's a need to loop through the results like usually.

Hope it helps


The difference is that you have more control over the arguments you use in wp_remote_post. But because you have more control, the defaults won't always be the same. For example; User Agent is usually empty with wp_remote_post but uses the browser name when submitting the form in your browser.

When you consume a POST request there isn't much difference. It's typically just the $_GET or $_POST ($_REQUEST for either) on the other end that holds key value pairs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.