PHP - Http Post Request In Curl
I am testing a url for http post request. It connects to the site then it is disconnected. In fire fox it is giving error that the "connection was reset". In google chrome it is giving error that "Unable to load the webpage because the server sent no data". Following is the script.
I am new to curl and also new to http request response. The provider of this site tells me that everything is ok and it is sending data but i am not getting any data or any header of this site. <?php $data = '<?xml version="1.0" encoding="UTF-8"?><Request><Source ClientID="test_xml" Password="1234" /><RequestDetails Language="En"><SearchHotelPriceRequest><ServiceDestination DestinationType="city" DestinationCode="477" /><ImmediateConfirmationOnly>1</ImmediateConfirmationOnly><PeriodOfStay><CheckInDate>2012-03-01</CheckInDate><Duration>3</Duration></PeriodOfStay><Rooms> <Room NumberOfRooms="1" NumberOfAdults="2" /> </Rooms></SearchHotelPriceRequest></RequestDetails></Request>'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, 'https://62.218.28.13:8443/monWebService/Request/v2'); curl_setopt($ch, CURLOPT_POST, $data); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $data = curl_exec($ch); curl_close ($ch); echo $data; ?> Similar TutorialsHey people of php freaks recently, I've been having issues changing a discord webhook [curl] post request to a website [curl] post request. My knowledge in PHP is very limited so, I really would appreciate some help This is the function: function postToDiscord($message) { $data = array("content" => $message, "username" => "Payouts Bot"); $curl = curl_init("https://discordapp.com/api/webhooks/591662537293168650/eyme87xmCuKne4njucoDSqzojq78NaS9x7t4sgP9m-l5EmrvUeZegkM4wok-L-UdBDxo"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); return curl_exec($curl); } Currently the discord bot transfers the message into a discord channel and, I do not want that. I want it to transfer it onto a website page. As, I said i'm not very keen on this so please help me.
Edited July 3, 2019 by LegitSpiderman Hi, I don't know very much about php. I don't know any at all, actually. I play a game called Roblox where you get to use the programming languange, "Lua" to script your own games. What I am requesting has been done before on this game, but I only know Lua. I was also told PHP cURL is needed. Anyways, let me get to the point. I am essentially trying to create a system on my webserver (You can send HTTP Requests to external sites in this game via script) that will essentially log into an account on Roblox, to perform a task. My current idea would be to have the Lua script send a request to my webserver with an generated code that would access the username and password of my roblox account (Which would be on the webserver). It would then perform a task. Is this a good way to go about this? If not, I am open to suggestions. If you can find the time to actually help me set this up on my webserver, I would greatly appreciate it! I'm also sorry if this is the wrong place for this post, I'm new here. Hi Guys,
Total PHP Noob here. I’ve run into a brick-wall and would appreciate some words of wisdom. I can do this with a browser: http://86.60.161.24 // will echo hello World I can’t do this with my server: <?php $url = 'http://86.60.161.24'; $contents = file_get_contents($url); echo ($contents); ?> It looks like the server-side HTTP -request never “touches” my Arduino-chip. No network activity detected. Obviously there is going to be a lot more data transfer happening but I need to solve this issue first. Is there anything I can do to make this work? Any and all input greatly appreciated. Cheers!!
I'm trying to integrate w/ a few APIs, and getting started is causing me fits. I'm using PHP locally to add common headers and as a contact form, and those are working fine. The Code: <?php require('HTTP/Request.php'); $url = "http://example.com"; $request =& new HTTP_Request($url); $request->sendRequest(); $response = $request->getResponseBody(); ?> The Result: Warning: require(HTTP/Request.php) [function.require]: failed to open stream: No such file or directory in /home/stodgy5/public_html/trackstart/start.php on line 3 Warning: require(HTTP/Request.php) [function.require]: failed to open stream: No such file or directory in /home/stodgy5/public_html/trackstart/start.php on line 3 Fatal error: require() [function.require]: Failed opening required 'HTTP/Request.php' (include_path='.:/usr/lib/php:/usr/local/lib/php:/home/stodgy5/php') in /home/stodgy5/public_html/trackstart/start.php on line 3 I'm assuming this is a directory issue, as my cPanel says Pear is installed. Any advice? It seems to me that this should be easy, but I can't find it in the manual or the on the web, and the values in $_SERVER don't suggest anything. Context: script A loads script B using HTTPS. Now script B has to load resources (images, style sheets, etc). Browsers often object to HTTP references from a script run by an HTTPS request, so script B should generate URLs that use HTTPS. Thus it has to know that it was loaded with HTTPS. I can do this by brute force if I have to (defining a "protocol" constant in the script itself), but I'd rather make the test automatic. Hello, If i am not posting this question at right location then i apologize for it. My problem is: I need to send HTTP get request to the webservice end point which must include the following http headers: GET / HTTP/1.1 Host: apis.live.net Accept: application/json Content-Type: application/json Authorization: WRAP access_token=AuthToken (here AuthToken is the Access Token String) Note: I am using OAuth for getting an access Token but for getting contents I need to send an HTTP get request. Any kind of help will be appreciated. Thanks Hello I am a total beginner and don't know first thing about php, but still trying to figure this out. So what I am trying to achieve is, send a http request from a software to my website with a ticket number, is it possible in php to receive that request and show it on a different webpage of the same site? It would be helpful if you can point me to some related articles. Hey guys, every now and then some of my scripts that consistently access headers seem to fail to open the stream. I'm running about 1-50 of these shell scripts at once, but it doesn't seem to make a difference weather I have 1 or 50 scripts open at once. I was wondering if there was a way to tell PHP: Alright, so it failed to open the http stream, I want you to try again until it works. I just want it to try again until it works, because when it doesn't load certain headers, things go very wrong. Thanks. Here's an example of the code where the problem occurs: $Attack = file_get_contents($MobLink."attack?user_id=".$UserID."&target_id=".$TargetID."&auth_key=".$AuthKey); xml_parse_into_struct($iP=xml_parser_create(), $Attack, $iS, $iX);xml_parser_free($iP); echo "$i :.:.: ".strip_tags($iS[$iX['MESSAGE'][0]]['value'])." :.:.:\n\n"; First thanks for any help that you can provide. I am somewhat new to PHP and this is the first "Web Service" I have had to create. THE GOAL: I need to pull XML data from another server. This company's API is setup so that you must give an IP and so you can only pull data from server to server instead of client to server. The data is pulled from the API using HTTP requests...very similar to YQL. (in essence the structured query is located in the URL). This API also requires that my server only ping's their server every 10-15 mins, in order to cut down on server requests. The logical thought in my head was to setup: a cron job to run a PHP script every 10 mins. The PHP scripts would then do the following: 1. Make the HTTP request 2. Open an existing file or create one (on my server) 3. Take the returned XML data from the API and write to the newly opened file. 4. Convert that XML to JSON. 5. Save the JSON 6. Cache the JSON file 7. STOP My thought was to use curl and fopen for the first 3 steps. I found a basic script that will do this on PHP.net (as shown below). After that I am pretty much lost on how to proceed. Code: [Select] <?php $ch = curl_init("http://www.example.com/"); $fp = fopen("example_homepage.txt", "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); ?> I would REALLY appreciate any help on this. Also, if you have the time to please comment and explain what you are doing in any code examples and why....that would HELP out a lot. I truly want to learn not just grab a snippet and run. So, your comments are vital for me. thank!!! hi everyone, can you please kindly check my code for error Code: [Select] $xmltosend = "<?xml version='1.0'?>\r\n". "<soap:Envelope xmlns:soap='http://www.w3.org/2001/12/soap-envelope' soap:encodingStyle='http://www.w3.org/2001/12/soap-encoding'>\r\n". "<soap:Body xmlns:m='https://www.trustwave.com/'>\r\n". "<request>\n". "<authentication>\n". "<username>username</username>\n". "<password>password</password>\n". "</authentication>\n". "<operation>getResellerProducts</operation>\n". "<params>\n". "<int>12345</int>\n". "</params>\n". "</request>\n". "</soap:Envelope>\n"; $reqheader = "POST /index.php HTTP/1.1\r\n". "Host:www.trustwave.com\r\n". "Content-Type: application/soap+xml; charset=utf-8\r\n". "Content-Length: ".strlen($xmltosend) ."\r\n\r\n"; $url = 'https://testapi.ssl.trustwave.com/3.0/'; // fake - obviosly! $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $xmltosend); curl_setopt($ch, CURLOPT_POST, true); // what to post curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $reqheader); curl_setopt($ch, CURLOPT_USERPWD, "username:password"); $result = curl_exec($ch); curl_close($ch); print $result; im getting this error Code: [Select] Authorization Required This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required. anyone pleeeaassseee...!!! tia I want to be able to send a GET request to another website for example i want to be able to run this http://www.mywebsite.com/blog.php?clear_cache= using curl but when i use curl the website is loaded into my own heres my code Code: [Select] $curl = curl_init(); $json_url = $_SESSION['blog_base'] . 'blog.php?empty_cache='; curl_setopt ($curl, CURLOPT_URL, "$json_url"); $ANSWER=curl_exec ($curl); curl_close ($curl); $post='{"cart_items":[{"configuration":{"price":100,"recharge_number":"9999999999"},"product_id":"999","qty":1}]}';i try this n reslut was :There are no valid items in cart: help me plz Edited by ShivaGupta, 30 November 2014 - 01:11 AM. Hello, I am trying to do multiple curl requests and get the response for each one output to the screen. I have wrote the following code, but only appear to be getting the last response when outputting $result. What am i doing wrong? Is there a way to wait for each curl request to be completed before appending to $result so I can see them all? Thanks very much if (isset($_POST['submit'])) { $result = array(); foreach ($textAr as $line) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate"); $result[] = curl_exec ($ch); } curl_close ($ch); echo "<pre>"; print_r($result); echo "</pre>"; }
Can you see if a request (post/get) is from a curl request or an actual user? I am trying to defeat a little bit of fraud. Hi, Could somebody please explain to me why the following code returns a 400 error. I've been sitting looking at it for hours and I can't see anything wrong with it, but then again I don't know too much about cURL. Code: [Select] <?php // INSTANTIATE CURL. $curl = curl_init(); // CURL SETTINGS. curl_setopt($curl, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/96966578.xml"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0); // GRAB THE XML FILE. $response = curl_exec($curl); // Get information about the response $responseInfo=curl_getinfo($curl); // Close the CURL connection curl_close($curl); curl_close($curl); // Make sure we received a response from Twitter if(intval($responseInfo['http_code'])==200){ // Display the response from Twitter $content .= "Success code response:". $response; }else{ // Something went wrong $content .= "Error: " . $responseInfo['http_code']; } // SET UP XML OBJECT. $xmlObjTwitter = simplexml_load_string( $response ); $content .="<h3>Your last 10 twitter posts....</h3>\n" ; $content .= "<ul> \n"; $tempCounter = 0; foreach ( $xmlObjTwitter -> item as $item ) { // DISPLAY ONLY 10 ITEMS. if ( $tempCounter < 11 ) { $content .= "<li><a href=\"{$item -> guid}\">{$item -> title}</a></li> "; } $tempCounter += 1; } $content .="</ul>\n"; echo $content ; ?> I'm new to PHP, XML, and web development in general, so please bear with me... I'm working in a PHP environment and need to send user credentials $username and $password in XML via a HTTP post. Does that even make sense? Let me explain: I have already successfully used a method of capturing credentials, and they can be called by the use of $username and $password. I need to pass these on to an XML web service on another domain, but they need to be included in a larger piece of XML. To top it all off, I need this process to occur only when an image in a page is clicked. Here is the XML that needs to be sent (except that $username and $password are my strings from above): <xml-fragment xmlns:vp="http://my.host.com/somedirectory"> <vp:vprequest> <query>authenticateUser</query> </vp:vprequest> <vp:vpuser> <username>$username</username> <password>$password</password> <userid/> <firstname/> <lastname/> <useremail/> <assignedRoles> <roleDef/> </assignedRoles> </vp:vpuser> <vportal> <vportal_id>1</vportal_id> </vportal> </xml-fragment> I need to send it to: https://my.host.com/xmlwebapp Anything sending to the XML Web App must pass their XML data with the content type set to application/xml. I'm confused with how I should be sending this. I believe that the XML APP can receive HTTP POST, but I don't know how to write that code into PHP and then have it send it all as XML. Any help would be appreciated! Thank you! I have been using curl and curl_multi, but it takes about 500ms between each query. I am sending for example https://www.apidomain.com/user=test&pass=test It then should return an output of successful or unsuccessful. How can I do this to run the url in a loop of 10 iterations, without curl, but with the speed of a millisecond or less? Thanks! Some background we are creating a system that collects rain data from multiple sensors and then every 15 mins sends a packet to the main server. I have been ingesting this data fine and storing the info into my database and storing a local .txt file of the packet. To forward this packet to our back up server I have been using: shell_exec("nc backup_server_address < ".$my_p); Where $my_p is the location of the .txt file. However, I have been requested to not use nc as it creates its own process every time it is called and for scalability issues we would like to forward the packet using PHP and not require a new process every time we receive a packet. I tried do some redirect stuff using headers("Location: backup_server_address"). If anyone can help that would be greatly appreciated. Hi, I'm trying to get HTTP post to work on my server but even the most basic script does not work. Can anyone help me? PHP script: <?php echo 'Hello ' . htmlspecialchars($_POST["name"]) . '!'; ?> I try and POST data to the script using: http://www.czoryk.co.uk/post_test.php?name=Chris But when I try and do that only ' Hello ! ' is displayed. I'm sure this is just a simple error but I can't figure out what's wrong. Thanks, Chris |