相当于这个jave代码到c#.net [英] Equivalent of this jave code to c#.net

查看:47
本文介绍了相当于这个jave代码到c#.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c#.net中这段代码的等价物是什么:

Hi, what is the equivalent of this code in c#.net:

package org.geonetwork.xmlservices.client;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.jdom.Document;
import org.jdom.Element;

public class GetGroupsClient {

  public static void main(String args[]) {
    **// Create request xml**
    Element request = new Element("request");
    **// Create PostMethod specifying service url**
    String serviceUrl = "http://localhost:8080/geonetwork/srv/en/xml.group.list";
    PostMethod post = new PostMethod(serviceUrl);

    try {
      String postData = Xml.getString(new Document(request));

      **// Set post data, mime-type and encoding**
      post.setRequestEntity(new StringRequestEntity(postData, "application/xml", "UTF8"));

      **// Send request**
      HttpClient httpclient = new HttpClient();
      int result = httpclient.executeMethod(post);

      **// Display status code**
      System.out.println("Response status code: " + result);

      **// Display response**
      System.out.println("Response body: ");
      System.out.println(post.getResponseBodyAsString());

    } catch (Exception ex) {
      ex.printStackTrace();

    } finally {
      **// Release current connection to the connection pool
      // once you are done**
      post.releaseConnection();
    }
  }
}





需要你的帮助吗?



Need your help please?

推荐答案

你应该尝试一些在线转换器至少进行代码转换。自己尝试一下,这里有几个代码转换器。

.NET代码转换 - 转换代码 [ ^ ]



以下提出具体问题。
You should have tried some online converters atleast for code conversion. Try it yourself, here few code converters.
.NET Code Conversion - Convert your code[^]

Hereafter come with specific questions.


了解Java代码正在做什么将使您的生活更轻松。它是 HTTP / REST / Servlet 调用 POST WebMethod。在Google上,您会找到很多链接,介绍如何在C#中执行此操作。



Google搜索结果
Understanding what Java code is doing will make your life easier. Its a HTTP/REST/Servlet call to a POST WebMethod. On Google you will find many links which describe how to do this in C#.

Google Search Result


这篇关于相当于这个jave代码到c#.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆