Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7593477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:10:44+00:00 2026-05-30T21:10:44+00:00

I have do post some information in cross domain . And i am achieving

  • 0

I have do post some information in cross domain . And i am achieving this thing by below code

<?php

  function do_post_request($sendingurl, $data, $optional_headers = null) {

    $params = array(
      'http' => array(
        'method' => 'POST',
        'url' => $data
      )
    );
    if ($optional_headers !== null) {
      $params['http']['header'] = $optional_headers;
    }
    $ctx = stream_context_create($params);

    $fp = @fopen($sendingurl, 'rb', false, $ctx);
    if (!$fp) {
      throw new Exception("Problem with $sendingurl, $php_errormsg");
    }

    $response = @stream_get_contents($fp);
    if ($response === false) {
      throw new Exception("Problem reading data from $sendingurl, $php_errormsg");
    }

    return $response;

  }

  $response = do_post_request('http://mag16.playtrickz.com/testing.php','http%3A%2F%2Fwww.facebook.com');
  echo $response;

But it is not working .
On successful POST Request : It will display its value
otherwise it will show : nodata found.
Why it is not working and how to make them work .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:10:45+00:00Added an answer on May 30, 2026 at 9:10 pm

    Here is how I would write your function:

    function do_post_request($url, $data = NULL, $optional_headers = NULL) {
    
      // Build a body string from an array
      $content = (is_array($data)) ? http_build_query($data) : '';
    
      // Parse the array of headers and strip values we will be setting
      $headers = array();
      if (is_array($optional_headers)) {
        foreach ($optional_headers as $name => $value) {
          if (!in_array(strtolower($name), array('content-type', 'content-length', 'connection'))) {
            $headers[$name] = $value;
          }
        }
      }
    
      // Add our pre-set headers
      $headers['Content-Type'] = 'application/x-www-form-urlencoded';
      $headers['Content-Length'] = strlen($content);
      $headers['Connection'] = 'close';
    
      // Build headers into a string
      $header = array();
      foreach ($headers as $name => $value) {
        if (is_array($value)) {
          foreach ($value as $multi) {
            $header[] = "$name: $multi";
          }
        } else {
          $header[] = "$name: $value";
        }
      }
      $header = implode("\r\n", $header);
    
      // Create the stream context
      $params = array(
        'http' => array(
          'method' => 'POST',
          'header' => $header,
          'content' => $content
        )
      );
      $ctx = stream_context_create($params);
    
      // Make the request
      $fp = @fopen($url, 'rb', FALSE, $ctx);
      if (!$fp) {
        throw new Exception("Problem with $url, $php_errormsg");
      }
    
      $response = @stream_get_contents($fp);
      if ($response === FALSE) {
        throw new Exception("Problem reading data from $url, $php_errormsg");
      }
    
      return $response;
    
    }
    

    This has been re-built so that the data to send to the server and the headers are passed in as associative arrays. So you would build an array that looks like you would want $_POST to look in the remote script, and pass that in. You can also pass an array of additional headers to send, but the function will automatically add a Content-Type, Content-Length and Connection header.

    So your request would be called like this:

    $data = array(
      'url' => 'http://www.facebook.com/'
    );
    $response = do_post_request('http://mag16.playtrickz.com/testing.php', $data);
    echo $response;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code like this: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Save([Bind(Prefix=)]Person person) { String s
Does anyone have some sample code showing how to POST to a URL using
I want to send some information from PHP to Java. Why? Because I have
I am creating a php script to post some information on a fan page
I'm stuck trying to solve this. I'm plotting some information that I have in
I have to POST some parameters to a URL outside my network, and the
I have a Rails app that will post some data to another Rails app.
I'm using httpc:request to post some data to a remote service. I have the
I have a post-build event that runs some commands for a c# project. The
Suppose you have a method with some pre and post-conditions. Is it ok to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.