将java代码转换为c#代码 [英] converting java code to c# code

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

问题描述

他们的,



我正在寻求帮助将我的Java代码转换为c#.net代码。

i一直在尝试最后两天使用SHARPEN和SOURCE-FORGE插件。但是他们没有进步。打破了我的脑袋:doh :: confused:

i din找到任何合适的资源来完成我的任务。





如果你知道的话,帮帮我

提前谢谢



hi their,

i'm looking for assistance to convert my Java code to c#.net code.
i have been trying for last two days using SHARPEN and SOURCE-FORGE plugins. but their is no progress.its breaking my heads :doh: :confused:
i din find any proper resource to accomplish my task.


if u know ,help me out
thanks in advance

package com.viadeo.servlets;
 
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.json.JSONException;
import org.json.JSONObject;
 
public class Oauth2SampleCodeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	 
	private static final String clientId = "[your client id]";
	private static final String clientSecret = "[your client secret]";
	 
	private static final String oauthBase = "https://secure.viadeo.com/oauth-provider";
	private static final String authorizeURL = oauthBase + "/authorize2";
	private static final String accessTokenURL = oauthBase + "/access_token2";
	private static final String apiBase = "https://api.viadeo.com";
	 
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	 
		String code = request.getParameter("code");
		String redirectUri = request.getRequestURL().toString();
		 
		if (code == null || "".equals(code)) {
		 
			// Step 1 - Redirect user to provider for authorization
			String url = authorizeURL + "?response_type=code&display=popup&lang=en&client_id="
			+ clientId + "&redirect_uri=" + redirectUri;
			response.sendRedirect(url);
		 
		} else {
		 
			// Step 2 - Exchange for access grant
			String urlParameters = "grant_type=authorization_code&client_id=" + clientId
			+ "&client_secret=" + clientSecret
			+ "&redirect_uri=" + redirectUri + "&code=" + code;
			 
			String resp = executePost(accessTokenURL, urlParameters);
			 
			String accessToken = "";
			try {
				JSONObject json = new JSONObject(resp);
				accessToken = json.getString("access_token");
			} catch (JSONException e) { }
			 
			// Step 3 - Create connection
			response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
			response.setHeader("Location", apiBase + "/me.xml?access_token=" + accessToken);
		}
	}
	 
	// POST request helper
	private String executePost(String targetURL, String urlParameters) {
	URL url;
	HttpURLConnection connection = null;
	try {
	// Create connection
	url = new URL(targetURL);
	connection = (HttpURLConnection) url.openConnection();
	connection.setRequestMethod("POST");
	connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
	connection.setRequestProperty("Content-Length",
	"" + Integer.toString(urlParameters.getBytes().length));
	connection.setRequestProperty("Content-Language", "en-US");
	 
	connection.setUseCaches(false);
	connection.setDoInput(true);
	connection.setDoOutput(true);
	 
	// Send request
	DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
	wr.writeBytes(urlParameters);
	wr.flush();
	wr.close();
	 
	// Get Response
	InputStream is = connection.getInputStream();
	BufferedReader rd = new BufferedReader(new InputStreamReader(is));
	String line;
	StringBuffer response = new StringBuffer();
	while ((line = rd.readLine()) != null) {
	response.append(line);
	response.append('\r');
	}
	rd.close();
	return response.toString();
	 
	} catch (Exception e) {
	e.printStackTrace();
	return null;
	} finally {
	if (connection != null) {
	connection.disconnect();
	}
	}
	}
}

推荐答案

而不是陈述问题陈述,更好的方法是分享问题/错误,看看是否有帮助。



现在,我不确定您对我们中的任何人有什么帮助。我们应该在这里看到什么问题?我们是否建议给你一些软件来做这个Java到C#?

即使,如果我们有一些软件可以做到这一点,那么你需要手动查看的错误很少。没有软件可以100%转换它。



所以,我建议你分享问题/错误和相关代码以获得帮助。
Instead of stating the problem statement, better would be to share the issue/error and see if it helps.

Right now, I am not sure how are you expecting any of us to help you. What is the question that we should look at here? Are we suppose to suggest some software to you that does this Java to C#?
Even, if we have some software that does it, there will mostly be few errors that you need to look at yourself manually. No software can convert it 100%.

So, I would suggest you to share the issues/error and related code to get help.


你有没有考虑过谷歌? ?

非常快速的搜索(不到一分钟)让我 Microsoft Java语言转换助手 [ ^ ]
Have you considered Google?
A very quick search (less than a minute) got me to Microsoft Java language conversion assistant[^]


import java.io.*;
import java.net.*;

public class Lookup 
{
	public static void main(String[] args) throws Exception 
	{
		System.out.println("Hello World!");
		String client = "api";
		String apikey = "ABQIAAAAdGnGSqPru2GZ5ZCwFZsLDhQM9mDvw_EbadXXtLQ5SlzX_s0ijA";
		String appver = "1.5.2";
		String pver = "3.0";
		String url = "http://www.yahoo.com";
		String uri = "https://sb-ssl.google.com/safebrowsing/api/lookup?client="+client+"&apikey="+apikey+"&appver="+appver+"&pver="+pver;//+"&url="+url;

		URL lookUrl = new URL(uri);
		HttpURLConnection htCon = (HttpURLConnection) lookUrl.openConnection();
		htCon.setDoInput(true);
		htCon.setDoOutput(true);
		
		//OutputStream os = htCon.getOutputStream();
		PrintStream pos = new PrintStream(htCon.getOutputStream());
		pos.println(2);
		pos.println("http://www.asdrediff.com");
		pos.println("http://www.yahooabds.com");
		pos.close();
		
		System.out.println("respose code:" + htCon.getResponseCode());
		BufferedReader br = new BufferedReader(new InputStreamReader(htCon.getInputStream()));
		String str = "";
		while((str = br.readLine()) != null) {
			System.out.println(str);
		}
		br.close();
		htCon.disconnect();	
		System.out.println("end");
	}
}


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

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