将给定的JAVA代码转换为C# [英] Convert given JAVA code to C#

查看:456
本文介绍了将给定的JAVA代码转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DefaultHttpClient httpclient = new DefaultHttpClient();

//创建请求参数列表

ArrayList< namevaluepair> postParameters = new ArrayList< namevaluepair>();

postParameters.add(new BasicNameValuePair(INSTITUTION_ID,isntitution_id));

postParameters.add(new BasicNameValuePair( AGGREGATOR_ID,aggregator_id));

postParameters.add(new BasicNameValuePair(MEMBER_ID,member_id));

postParameters.add(new BasicNameValuePair( PASSWORD,password));

postParameters.add(new BasicNameValuePair(inputJson_,json string));

//打开新的POST请求连接url

HttpPost httpPost = new HttpPost(url);

httpPost.setEntity(new UrlEncodedFormEntity(postParameters));

//执行POST请求

HttpResponse response = httpclient.execute(httpPost);



我尝试过:



i我不知道JAVA代码,所以我没有尝试

DefaultHttpClient httpclient = new DefaultHttpClient();
// Create Request parameters list
ArrayList<namevaluepair> postParameters = new ArrayList<namevaluepair>();
postParameters.add(new BasicNameValuePair("INSTITUTION_ID", "isntitution_id"));
postParameters.add(new BasicNameValuePair("AGGREGATOR_ID", "aggregator_id"));
postParameters.add(new BasicNameValuePair("MEMBER_ID", "member_id"));
postParameters.add(new BasicNameValuePair("PASSWORD", "password"));
postParameters.add(new BasicNameValuePair("inputJson_", "json string"));
// Open new POST Request connection for the "url"
HttpPost httpPost = new HttpPost("url");
httpPost.setEntity(new UrlEncodedFormEntity(postParameters));
// Execute POST request
HttpResponse response = httpclient.execute(httpPost);

What I have tried:

i am not aware of JAVA Code so i have nothing try

推荐答案

HttpClient httpclient = new HttpClient();   
var postParameters = new List<KeyValuePair<string, string>>();
postParameters.Add(new KeyValuePair<string,string>("INSTITUTION_ID", "isntitution_id");
postParameters.Add(new KeyValuePair<string,string>("AGGREGATOR_ID", "aggregator_id"); 
postParameters.Add(new KeyValuePair<string,string>("MEMBER_ID", "member_id");
postParameters.Add(new KeyValuePair<string,string>("PASSWORD", "password");


postParameters.Add(new KeyValuePair<string,string>("inputJson_", "json string");
// Open new POST Request connection for the "url"
var content = new FormUrlEncodedContent(postParameters);

var response = await httpclient .PostAsync(url, content);

var responseString = await response.Content.ReadAsStringAsync();





不要直接复制粘贴代码。首先调试并确定是否在某些行中出现任何错误上面提到然后找出问题,如果你不能解决发表你的意见,如果你找到任何问题并解决了你自己然后评论你如何解决



Don't just Copy paste the code directly .first debug and identify if you are getting any errors in some lines mentioned above then find out the problem and if you aren't able to solve post your comments and if you find any issues and solved it your own then comment how you resolved as well


这篇关于将给定的JAVA代码转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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