Jump to content


Photo

Problem with Curl and post data

curl post php form

  • Please log in to reply
No replies to this topic

#1 9Rizla9

9Rizla9

    Newbie

  • New Members
  • Pip
  • 1 posts

Posted 31 January 2013 - 06:37 AM

Hi everyone,
this is my first post, because I need to pick your brains a bit :)
Any help is appreciated. Thx
...
I'm designing an application for purposes known to just a few people :) . It's work related.
It should take the data provided and insert into form provided below, and automatically submit it. There are no issues on any other page on that domain, I'm able to login, save cookies, read them, go to other links on the same site.
The problem I'm having is occurring on the page with the form, specifically, curl executes and fetches the page, but the post data is not sent.(data is sent as array, also tried urlencoded string) It think there might be a problem with the way the form is structured(code below). Also, the site with the form is not mine, but i will provide headers and post variable that are transmitted when form is submitted in browser.

So to begin. Form:


<form action="newFault" method="GET" id="typeForm">
<div style="margin:5px">
Tip smetnje:
<select name="type" id="type">
<option value="SVA" selected>SVA VA</option>
<option value="SNBS">SNBS - NBSA</option>
<option value="SULL">SULL - ULL</option>
</select>
</div>
</form>
<div>
<form method="POST" action="createFault" enctype="multipart/form-data">
<input type="hidden" name="type" value="SVA">
<table class="tableLight" cellpadding="0" cellspacing="1" style="margin: 5px;">
<tr>
<td colspan="2" style="text-align: right">Virtual account code:</td>
<td><input name="accountCode" size="60"></td>
<td></td>
</tr>
<tr>
<th>konos</th>
<th style="text-align: right">Kontakt osoba:</th>
<td><input name="param.konos" size="60"></td>
<td></td>
</tr>
<tr>
<th>tel</th>
<th style="text-align: right">Telefon:</th>
<td><input name="param.tel" size="60"></td>
<td></td>
</tr>
<tr>
<th>tfx</th>
<td style="text-align: right">Telefax:</th>
<td><input name="param.tfx" size="60"></td>
<td></td>
</tr>
<tr>
<th>eml</th>
<td style="text-align: right">E-mail:</td>
<td><input name="param.eml" size="60"></td>
<td></td>
</tr>
<tr>
<th>vrkv</th>
<th style="text-align: right">Vrsta:</th>
<td><input name="param.vrkv" size="60"></td>
<td></td>
</tr>
<tr>
<th>lpb</th>
<td style="text-align: right">Lokalni pozivni broj:</td>
<td><input name="param.lpb" size="60"></td>
<td></td>
</tr>
<tr>
<th>idkod</th>
<th style="text-align: right">nesto pristupa:</th>
<td><input name="param.idkod" size="60"></td>
<td></td>
</tr>
<tr>
<th>ugbrz</th>
<td style="text-align: right">brzina:</td>
<td><input name="param.ugbrz" size="60"></td>
<td></td>
</tr>
<tr>
<th>iatk</th>
<th style="text-align: right; ">Name:</th>
<td><textarea name="param.iatk" cols="40" rows="3"></textarea></td>
<td></td>
</tr>
<tr>
<th>dkk</th>
<td style="text-align: right">Datum koji odredi krajnji korisnik (ukoliko je to primjenjivo):</td>
<td><input name="param.dkk" size="60"></td>
<td></td>
</tr>
<tr>
<th>opkv</th>
<th style="text-align: right">Opis kvara:</th>
<td><textarea name="param.opkv" cols="40"></textarea></td>
<td></td>
</tr>
<tr>
<th colspan="2" style="text-align: right">Dokumentacija u TIFF formatu:</th>
<td><input type="file" name="attachment"></td>
<td></td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">
<input type="submit" value="Pozovi">

PHP code:


function saljipostom()
{
$postdata = 'type=SVA&accountCode=101010&param.konos=osoba&param.tel=016000840&param.tfx=&param.eml=&param.vrkv=vrsta&param.lpb=&param.idkod=02637992641&param.ugbrz=&param.iatk=imekorisnika&param.dkk=&param.opkv=opis&attachment=&submit=Pozovi';
$fields = array(
'type'=>'SVA',
'accountCode'=>'101010',
'param.konos'=>'osoba',
'param.tel'=>'016000840',
'param.tfx'=>'',
'param.eml'=>'',
'param.vrkv'=>'vrsta',
'param.lpb'=>'',
'param.idkod'=>'02637992641',
'param.ugbrz'=>'',
'param.iatk'=>'imekorisnika',
'param.dkk'=>'',
'param.opkv'=>'opis',
'attachment'=>''
);
$polje = $fields;
foreach ( $fields as $key => $value)
{
$post_items[] = $key . '=' . urlencode($value);
}
$post_string = implode ('&', $post_items);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://something.something/ui/ganimed/b2b/newFault?type=SVA");
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'curl/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'curl/cookies.txt');
$result = curl_exec ($ch);
curl_close ($ch);
unset($ch);
$page = str_get_html($result);
echo $page;
}



Response header from curl:

HTTP/1.1 200 OK Date: Thu, 24 Jan 2013 08:05:17 GMT Content-Type: text/html;charset=UTF-8 Content-Language: en-US Vary: Accept-Encoding Transfer-Encoding: chunked



Firebug says post fields are:

typeSVA
accountCode
param.konos
param.tel
param.tfx
param.eml
param.vrkv
param.lpb
param.idkod
param.ugbrz
param.iatk
param.dkk
param.opkv
attachment


Headers in firebug when form is submitted in browser:
Response Headers:
Connection Keep-Alive
Content-Language en-US
Content-Length 0
Content-Type text/plain
Date Thu, 24 Jan 2013 12:52:46 GMT
Keep-Alive timeout=15, max=100
Location https://something.something/ui/something/b2b/faults?type=SVA&guid=40898022-1b33-42ab-a9f2-696cc5f70950
Request Headers:

Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection keep-alive
Cookie JSESSIONID=DD0148C1D1701FA237704C42DE093687.node1
Host something
Referer https://something.something/ui/something/something/newFault?type=SVA
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0

QUestion: The problem I'm having is occurring on the page with the form, specifically, curl executes and fetches the page, but the post data is not sent, i.e. form is not accepting it(data is sent as array, also tried urlencoded string) ANy ideas?

Anything else you need just ask.

Edited by 9Rizla9, 31 January 2013 - 06:38 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com