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 8715399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:50:04+00:00 2026-06-13T05:50:04+00:00

So the title is self descriptive. Here is my php code function do_post_request($url, $data,

  • 0

So the title is self descriptive. Here is my php code

function do_post_request($url, $data, $optional_headers = null)
{
    $url = 'http://localhost:1181/WebSite1/PostHandler.ashx';
    $data = array( 'fprm' => 1, 'sprm'=> 2, 'tprm'=>3
                  );

  $params = array('http' => array(
              'method' => 'POST',
              'content' => $data
            ));

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

  //debug($params);
  //die();
  $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;
}

and here is my handler code:

 public void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "text/plain";
    string responseStr = "Hello World, this reply is from .net";
    string fprm = context.Request["fprm"];
    string sprm = context.Request["sprm"];
    string tprm = context.Request["tprm"];
    context.Response.Write(responseStr + " " + fprm + " " + sprm + " " + tprm);

}

and this is the reply i am getting:

'Hello World, this reply is from .net   '

i.e. without the parameters value, I read a similar post and the idea I got was that maybe you need to set a different context type to pass content parameters. But looking throught the php documentation, I dont find any option, http://php.net/manual/en/context.http.php, for setting the context type

Any help would be great, thanks

  • 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-06-13T05:50:06+00:00Added an answer on June 13, 2026 at 5:50 am

    You’re just forgetting to set the content-type header on your stream context. Set it to application/x-www-form-urlencoded

    And you can’t pass an array as the content directly to the stream context, it has to be the urlencoded form string, so use http_build_query for that

     $params = array('http' => array(
                  'method' => 'POST',
                  'header'=>'Content-Type: application/x-www-form-urlencoded',
                  'content' => http_build_query($data)
                ));
    

    The reason you didn’t find how to change the content type on php’s stream context documentation is because they don’t provide a wrapper for that, but they do provide a way for you to add any HTTP header you want.

    This content-type is necessary because otherwise the requested server-side application would just end up with a string that it doesn’t know how to handle, since teorically you could send any kind of data over the content of a http request. application/x-www-form-urlencoded is telling the server that the string sent as the content is just a regular html form serialized and urlencoded. http_build_query takes a relational array and serializes it like a html form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, title self describes it.. I need to run a sql function to clean
I hope the title is self explanatory. Here is my HTML (there are many
I'm often having code written as follows try: self.title = item.title().content.string except AttributeError, e:
I think the title is self explanatory. What I'm looking for is material so
I believe the title is self-explanatory. How do you create the table structure in
Title is quite self explanatory, but I have some animation being done in a
The title is pretty self explanatory, but basically I need the table row to
The title is pretty self-explanatory. When I run my app on Netbeans (Tomcat 7),
The title is pretty self-explanatory: does anyone know of a (good) properties file reader
I have written this code for a search page in PHP and I would

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.