At first I'm really sorry for my bad English :icon_redface:

I really want to simulate a ImageButton click for an ASP.NET (.aspx) file via curl (or simplate HTML file, but I very tries for it and finally I didn't get it!

More explain...
I have this snippet code on Default.aspx.cs that I want to simulate it through curl.

protected virtual void MyIBtn_Click(object sender, ImageClickEventArgs e)
        Response.Write("Image Button Clicked!");

Now I want to get this result via curl. I try this but this is not working!

$aspx = curl_init('http://mysite.com/MyWeb/Default.aspx');
curl_setopt($aspx, CURLOPT_USERAGENT, 'Firefox');
curl_setopt($aspx, CURLOPT_RETURNTRANSFER, true);
curl_setopt($aspx, CURLOPT_POST, true);
curl_setopt($aspx, CURLOPT_POSTFIELDS, array(
	'MyIBtn_x' => '0',
	'MyIBtn_y' => '0'
echo curl_exec($aspx);

and this is HTML that I want to simulate it

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	Untitled Page
<form name="ctl01" method="post" action="http://mysite.com/MyWeb/Default.aspx" id="ctl01">
<input name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTEzODk5NzQ4MWQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFBk15SUJ0bmXldSN54bOFxnGm5yZDVvjTHfvk" type="hidden">


	<input name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwKghvXDAQK4ookeArro0fgO0i7R2lalHTpHY1Qz9NjPEsU9qDo=" type="hidden">
	<input name="MyIBtn" id="MyIBtn" src="" style="border-width: 0px;" type="image">

When I investigate for this problem I understood it's maybe for difference sender because for real ImageSubmitButton it's System.Web.UI.WebControls.ImageButton while for another it's not!

Note: I haven't access to source ASP.NET file on the server.


Edited by sunrise2008: n/a

7 Years
Discussion Span
Last Post by dirtfox

WOW! If figured out this problem! I used these postfields.

curl_setopt($aspx, CURLOPT_POSTFIELDS, array(
	'MyIBtn.x' => '0',
	'MyIBtn.y' => '0'

Just put "." instead of "_" and problem solved as easy!!!

Edited by sunrise2008: n/a


this is helpful and looks like what i need. is the array corresponding to the "name" or the "id"?

<input name="MyIBtn" id="MyIBtn"

like say for example it's

<input name="MyIBtn" id="My_Button"

How would it be

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.