Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
PHP Code:
Code 1:
PHP
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'http://www.mirrorupload.net/api/server.html');
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
$output = curl_exec($ch);
curl_close($ch);


Code 2:
PHP
$postmember = array ();
$postmember['login'] = 'Your login';
$postmember['pass'] = 'Your password';
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'http://www.mirrorupload.net/api/member.html');
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postmember);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
$output = curl_exec($ch);
curl_close($ch);


Code 3:
PHP
$postfile = array ();
$postfile['file'] = '@path_file';
$postfile['session_id'] = 'Your Session_id';
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'See above');
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postfile);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
$output = curl_exec($ch);
curl_close($ch);



I am new to c# and don't know anything about php. I was trying to upload files automatically using api. I search the net form POST methods and Webrequest and stuff but I really don't know how to include these thing in my C# program. So, it'll be really helpful if somebody explains what actually those codes mean and their equivalent c# code. Please convert these codes to C# for me. It would make sense.
Posted
Updated 1-Sep-12 1:11am
v3
Comments
AmitGajjar 1-Sep-12 8:18am    
What you mean by uploading files automatically. there should be some event or at particular time when you can upload your image. so when exactly you want to upload your image?

1 solution

These snippets use the CURL[^] api, as described here[^]. There is a .net port[^] of curl api, but I think you should use the HttpClient class[^], as described here:
http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx[^]
http://alexmg.com/post/2009/04/07/Introduction-to-the-HttpClient.aspx[^]
 
Share this answer
 
Comments
[no name] 1-Sep-12 7:20am    
I still have big confusions. If you can convert at least one of those codes that'd be very helpful. Else just tell me what is the equivalent line in c# for this line
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postmember);
Zoltán Zörgő 1-Sep-12 12:11pm    
This line of code simply adds to the http request body the content of the $postmember associative array, that contains the authentication credentials required by the actual site. Ok, but now I understand what your problem is - although I don't know what you need exactly. You have lack of general knowledge about the http protocol. Read this one: http://www.jmarshall.com/easy/http/ (trust me, this is the shortest version). And download the Curl .net port from the link I have given: http://sourceforge.net/projects/libcurl-net/ . The package contains lots of examples.
[no name] 1-Sep-12 12:28pm    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900