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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:45:24+00:00 2026-05-16T18:45:24+00:00

I need to do a post to a url which need to be authenticated

  • 0

I need to do a post to a url which need to be authenticated first, in C#, i can do this

    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
    myRequest.Method = "POST";
    myRequest.ContentType = "application/x-www-form-urlencoded";
    myRequest.Credentials = new NetworkCredential(username, password);
    myRequest.PreAuthenticate = true;

    Stream newStream = myRequest.GetRequestStream();
    newStream.Close();

    // Get response
    try
    {
        HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
        return response.StatusDescription;

        // some other code 
    }
    catch (Exception ex)
    {
        return ex.Message;
    }

how to do this in php?

  • 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-16T18:45:25+00:00Added an answer on May 16, 2026 at 6:45 pm

    An example using cURL:

    <?php
    $url = "http://example.com/";
    $username = 'user';
    $password = 'pass';
    // create a new cURL resource
    $myRequest = curl_init($url);
    
    // do a POST request, using application/x-www-form-urlencoded type
    curl_setopt($myRequest, CURLOPT_POST, TRUE);
    // credentials
    curl_setopt($myRequest, CURLOPT_USERPWD, "$username:$password");
    // returns the response instead of displaying it
    curl_setopt($myRequest, CURLOPT_RETURNTRANSFER, 1);
    
    // do request, the response text is available in $response
    $response = curl_exec($myRequest);
    // status code, for example, 200
    $statusCode = curl_getinfo($myRequest, CURLINFO_HTTP_CODE);
    
    // close cURL resource, and free up system resources
    curl_close($myRequest);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working in simple application in which I need to post data to
I'm trying to POST data to an external url using HttpWebRequest, then i need
I need to update a json list of object via url post data. For
I need to call an API with POST arguments, for example: URL = http://localhost/myAPI/
I need to post in the background with Greasemonkey. I tried to create an
I need to post a form on a new website which is UTF-8 encoded.
I need to post some text to a remote server over HTTP, this server
In my app, I have this scenario where I need to post an object
I would like to ask about the button and the url post method in
I need to work with REST api in android application which is created by

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.