ibinod Posted September 7, 2009 Share Posted September 7, 2009 Hi, i am trying to make a simple code that can submit content automatically using curl i have the following code This is to login to the site which works perfectly $curl_connection = curl_init("http://www.familyfriendsphotos.com/login.php"); curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 300); curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($curl_connection, CURLOPT_POST, 1); curl_setopt($curl_connection, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($curl_connection, CURLOPT_AUTOREFERER, true); curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_connection, CURLOPT_TIMEOUT, 10); curl_setopt($curl_connection, CURLOPT_COOKIEJAR, ‘cookie.txt’); curl_setopt($curl_connection, CURLOPT_COOKIEFILE, ‘cookie.txt’); $post_data['uname'] = $dir['user']; $post_data['pswd'] = $dir['pass']; $post_data['Submit']="Login"; foreach ( $post_data as $key => $value) { //echo ("Key:".$key."=>".$value); $post_items[] = $key."=".$value; } $post_string = implode ("&", $post_items); //echo $post_string; curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); $result = curl_exec($curl_connection); unset($post_data); and to submit the article i have the following code curl_setopt($curl_connection, CURLOPT_URL, 'http://www.familyfriendsphotos.com/submitart.php'); $post_data['author'] = $article['author']; $post_data['parentId'] = $article['cat']; $post_data['f_arttitle'] = $article['title']; $post_data['f_artsummary'] = $article['short_desc']; $post_data['f_artbody'] = $article['article']; $post_data['f_artres'] = $article['resource']; $post_data['f_artkey'] = $article['keywords']; $post_data['key']="avachars_key"; $post_data['submit'] = "Submit"; foreach ( $post_data as $key => $value) { $post_items[] = $key."=".$value; } $post_string = implode ("&", $post_items); curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); $result = curl_exec($curl_connection); echo ($result); curl_close($curl_connection); But i get invalid http request like this ERROR The requested URL could not be retrieved While trying to process the request: POST /thankyou.php HTTP/1.1 Host: www.familyfriendsphotos.com Accept: */* Accept-Encoding: gzip,deflate Referer: http://www.familyfriendsphotos.com/thankyou.php Cookie: PHPSESSID=5f2127a0cd9045e3f38d1ab0b3684d2f Content-Length: 3585 Content-Type: application/x-www-form-urlencoded Expect: 100-continue The following error was encountered: * Invalid Request Some aspect of the HTTP Request is invalid. Possible problems: * Missing or unknown request method * Missing URL * Missing HTTP Identifier (HTTP/1.0) * Request is too large * Content-Length missing for POST or PUT requests * Illegal character in hostname; underscores are not allowed Please tell me what should i do to fix this Quote Link to comment https://forums.phpfreaks.com/topic/173403-posting-values-using-curl-invalid-http-request/ Share on other sites More sharing options...
l0ve2hat3 Posted September 13, 2009 Share Posted September 13, 2009 try removing curl_setopt($curl_connection, CURLOPT_ENCODING, 'gzip,deflate'); your not actually compressing it so it might be confusing the server Quote Link to comment https://forums.phpfreaks.com/topic/173403-posting-values-using-curl-invalid-http-request/#findComment-917456 Share on other sites More sharing options...
ngreenwood6 Posted September 13, 2009 Share Posted September 13, 2009 in the second file you have no $curl_connection defined unless it is just not shown in your post. If not you need to add this above the first line on the second file you showed : $curl_connection = curl_init(); Quote Link to comment https://forums.phpfreaks.com/topic/173403-posting-values-using-curl-invalid-http-request/#findComment-917565 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.