Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
hi pl help me in converting the following code to c#

C#
HttpPost httpPost = new HttpPost("http://www.inspire-geoportal.eu/INSPIREValidatorService/resources/validation/inspire");
//xml response: httpPost.addHeader("Accept", "application/xml");
//html response
httpPost.addHeader("Accept", "text/html");
FileBody dataFile = new FileBody(new File("yourMetadataFile.xml"));
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("dataFile", dataFile);
httpPost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
switch (statusCode) {
    //OK
    case 200:   //implement the below method to extract the response
                parseServiceResponse(response);
                break;
    //Exception was thrown
    case 400:   //implement the below method to handle the exceptions
                handleServiceException(response);
                break;
    //Internal error from the service
    default:    //implement the below method to handle errors such as internal server error
                handleServerError(response);
Posted
Updated 30-Oct-11 19:58pm
v4
Comments
Sergey Alexandrovich Kryukov 31-Oct-11 0:40am    
To C#?! And what is the language of you sample then?
--SA
Mehdi Gholam 31-Oct-11 0:46am    
It could be java.
Sergey Alexandrovich Kryukov 31-Oct-11 1:11am    
Yes, Java naming style... thank you, Mehdi.
OP needs to specify it.
--SA
BillWoodruff 31-Oct-11 1:28am    
I think you could improve this question by adding a brief statement of exactly what you want to do ... before the code.

Something like: I want know how in C# to compose the equivalent of a (Java ?) "httpost," supply its required parameters, execute it, and then, based on the response code, I want to ...

1 solution

If you want to request a "POST" method on C#.You should use :
C#
string data; // SENDING DATA
           byte[] buffer = Encoding.UTF8.GetBytes(data);
           HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create("http://www.inspire-geoportal.eu/INSPIREValidatorService/resources/validation/inspire");
           hwr.Method = "POST";
           hwr.ContentType = "application/x-www-form-urlencoded";
           hwr.ContentLength = buffer.Length;
           Stream PostStream = hwr.GetRequestStream();
           PostStream.Write(buffer, 0, buffer.Length);
           PostStream.Close();


But i dont know about file code part.
 
Share this answer
 
v2

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