English 中文(简体)
您主机( VS dev 服务器) 的软件中止了已建立的连接( VS dev 服务器)
原标题:An established connection was aborted by the software in your host machine (VS dev server)

我曾经看到过类似的有关这个问题的文章, 但其中都与使用视觉演播室开发服务器 用于ASP.NET无关。

我收到以下错误 。

<% 1> 您主机 的软件中止了已建立的连接 。

我执行以下代码:

String employeesJson = client.downloadString("http://localhost:60000/Api/Employee/GetEmployees.aspx");

当我在一个普通的网络浏览器(21世纪或10世纪互联网探索器)中运行这个时,它运行很好。我得到了我想要的JSON结果。

我的 WebClient 类(在变量“client ”下)被使用,定义如下。

public class WebClient {

    private HttpClient httpClient;

    public WebClient() {

        httpClient = new DefaultHttpClient();

    }

    public String downloadString(String url) throws IOException {

        HttpGet get = new HttpGet(url);

        try {

            HttpResponse response = httpClient.execute(get); //this is where the error occurs.
            HttpEntity entity = response.getEntity();
            if(entity != null) {

                InputStream stream = entity.getContent();
                InputStreamReader streamReader = new InputStreamReader(stream);

                BufferedReader bufferedReader = new BufferedReader(streamReader);
                StringBuilder builder = new StringBuilder();

                String line = null;
                try {
                    while ((line = bufferedReader.readLine()) != null) {
                        builder.append(line + "
");
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        stream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                return builder.toString();

            }

        //catch all the types of exceptions this method can throw. catching "Exception" is considered bad.
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        }

        return null;

    }

}

我的机器人Manifest.xml文件看起来是这样的:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="specialisering.android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
最佳回答

我不敢相信我没有从文件上寻求答案。 它明确指出127.0.0.1是模拟器本身的IP,而10.0.2.2是开发机的IP。

从本地主机到10.0.2.2 解决了我的问题。

问题回答

防火墙停止了防火墙...所以关闭了防火墙,





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签