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

  • Home
  • SEARCH
  • 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 7617893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:15:36+00:00 2026-05-31T03:15:36+00:00

I have a hosted server with curl installed, but not http_post_data() pecl. I’m trying

  • 0

I have a hosted server with curl installed, but not http_post_data() pecl.

I’m trying to translate this (working) http_post_data() code to curl:

$responseString = @http_post_data("http://" . $this->username . ":" . $this->password ."@" . $this->webserviceHost . $this->requestUriBase .$request,
    $requestString,
    array('http_auth' => $this->username . ":" . $this->password, 'headers' => array('Content-Type' => 'text/xml')));

I’ve tried:

$url = "http://" . $this->username . ":" . $this->password ."@" . $this->webserviceHost . $this->requestUriBase .$request;
        curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-Type: application/xml'));
        curl_setopt($this->curl, CURLOPT_URL, $url);
        curl_setopt($this->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt(CURLOPT_USERPWD, "[$this->username]:[$this->password]");
        curl_setopt ($this->curl, CURLOPT_POST, true);
        curl_setopt ($this->curl, CURLOPT_POSTFIELDS, array($requestString));
        $content = curl_exec($this->curl);  

… and failed: couldn’t connect to host

What’s the correct code?

  • 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-31T03:15:37+00:00Added an answer on May 31, 2026 at 3:15 am

    To configure and execute a CURL request, I suggest the following format:

        # in curl URL is scheme://hostname/rest, and hostname != authority
        #     (authority is hostname plus port and with user/pass in front)
    
        $url = sprintf('http://%s/%s', $this->webserviceHost
                        , $this->requestUriBase . $request);
        $options = array(
             CURLOPT_HTTPHEADER     => array(
                 'Accept: application/xml', 
                 'Content-Type: application/xml',
             ),
             CURLOPT_HTTPAUTH       => CURLAUTH_BASIC,
             # don't use the brackets []
             CURLOPT_USERPWD        => $this->username . ':' . $this->password,
             CURLOPT_POST           => TRUE,
             CURLOPT_POSTFIELDS     => $requestString,
             CURLOPT_RETURNTRANSFER => TRUE,
        );
    
        $this->curl = curl_init($url);
        $r = curl_ setopt_ array($this->curl, $options);
        if (!$r) throw new Exception('Failed to setup options.');
        $content = curl_exec($this->curl); # This needs CURLOPT_RETURNTRANSFER => TRUE
    

    I’m not sure about CURLOPT_POSTFIELDS because you don’t have specified what $requestString contains. It’s likely that this setting above is wrong. See curl POST format for CURLOPT_POSTFIELDS.

    Edit: You have specified it via http_post_data:

    String containing the pre-encoded post data

    Curl supports that as well, just don’t pass as array, pass it as string:

         CURLOPT_POSTFIELDS     => $requestString,
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to upgrade my subversion server (I have it hosted with Dreamhost) This
This question is server oriented. I have a hosted server (a rather small one,
I have Bugnet installed on my hosted server and it does work, seems that
We are having two load balancing server. In that we have hosted a asp.net
I have a remoting server hosted under IIS that is throws the following exception
We have a client whose site is hosted on a server (I don't want
I have a flex app that is hosted on my server. It runs off
I have a web service that serves widgets. It is hosted on a server
I have an environment where multiple sites hosted on the same server will use
I have a site developed in ASP.NET and hosted on a windows server using

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.