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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:17:38+00:00 2026-05-28T06:17:38+00:00

I want to send a put request to an API which wants the details

  • 0

I want to send a put request to an API which wants the details of the request as XML

Apparently I need to send the xml as a file when using PUT with PHP.

How can I do this?

Here is what I’m trying:

$HttpSocket = new HttpSocket();
$result = $HttpSocket->put($put, $fh);

where $put is the url and $fh is a file i have made on the fly like this

$xmlObject = Xml::fromArray($xmlArray);
$xmlString = $xmlObject->asXML();

$fh = fopen('php://memory', 'rw');  
fwrite($fh, $xmlString);  
rewind($fh);  
  • 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-28T06:17:39+00:00Added an answer on May 28, 2026 at 6:17 am

    I ended up doing this just using php rather than the php helpers

    # write data into a temporary file
    $putData = "<subscription><productPath>$new_product_path</productPath></subscription>";
    $putDataFile = tmpfile();
    fwrite($putDataFile, "<subscription><productPath>$new_product_path</productPath></subscription>");
    fseek($putDataFile, 0);
    
    # initialize PUT call
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://api.example.com");
    curl_setopt($ch, CURLOPT_PUT, true);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/xml"));
    curl_setopt($ch, CURLOPT_INFILE, $putDataFile);
    curl_setopt($ch, CURLOPT_INFILESIZE, strlen($putData));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    # executes PUT call and clean up
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);
    fclose($putDataFile);
    curl_close($ch);
    

    I’d have preferred using the Cake classes for neatness, but this works with the api i was using.

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

Sidebar

Related Questions

I want to send a xml file to my wcf service , how can
My data is an xml element & I want send PUT request with JavaScript.
I have a curl request as below, which should send a PUT request to
I want to send a request via Viralheat's API in my controller's update method
I want to send array of my own objects to JSP page by request.
Rails 3 question. If i send a request like this PUT http://myapp/posts/123?post [title]=hello then
I've created a RESTful API that supports GET/POST/PUT/DELETE requests. Now I want my API
i want to send JSON with POST/PUT i don't know if it's the same
I want to send request to j_security_check from servlet and get auth cookie from
Is it possible to use an NSURLConnection/NSURLRequest combination to send a PUT request 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.