Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# PHP
PHP Code:
Code 1:
$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:
$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:
$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 1-Sep-12 0:54am
Edited 1-Sep-12 1:11am
v3
Comments
@amitgajjar at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Comments
Kaushik Deb Biswas at 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ő at 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.
Kaushik Deb Biswas at 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)

  Print Answers RSS
0 OriginalGriff 490
1 Gihan Liyanage 338
2 ChauhanAjay 180
3 Vinay Mistry 160
4 Sergey Alexandrovich Kryukov 138
0 Sergey Alexandrovich Kryukov 9,011
1 OriginalGriff 7,941
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 1 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100