GVKun编程网logo

尝试使用 dio 传递客户端证书时获取空白 httpException 消息(尝试使用代理是什么意思)

14

对于尝试使用dio传递客户端证书时获取空白httpException消息感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍尝试使用代理是什么意思,并为您提供关于ABP:FlurlHttpExcep

对于尝试使用 dio 传递客户端证书时获取空白 httpException 消息感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍尝试使用代理是什么意思,并为您提供关于ABP:FlurlHttpException涵盖了UserFriendlyException、apache http客户端org.apache.http.NoHttpResponseException:目标服务器无法响应、asp.net-mvc – HttpResponseException和HttpException之间有什么区别?、c# – HttpClient.SendAsync HttpException:客户端已断开连接的有用信息。

本文目录一览:

尝试使用 dio 传递客户端证书时获取空白 httpException 消息(尝试使用代理是什么意思)

尝试使用 dio 传递客户端证书时获取空白 httpException 消息(尝试使用代理是什么意思)

如何解决尝试使用 dio 传递客户端证书时获取空白 httpException 消息?

我在尝试使用 dio 包提交客户端证书时收到空白的 httpException 消息。 dioErrorType (dioErrorType.DEFAULT) : HttpException (HttpException:,uri = [API_PATH])

向邮递员请求时,相同的证书有效。

HTTP/1.1 200 OK
transfer-encoding: chunked
Content-Type: application/json; charset=utf-8
content-encoding: gzip
vary: Accept-Encoding
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
Date: Thu,21 Jan 2021 05:56:55 GMT 

下面是我使用的代码

 Future<List<int>> loadCertificate(String assetPath) async {
    return (await rootBundle.load(assetPath)).buffer.asUint8List();
  } 
final List<int> certificateChainBytes =
        await loadCertificate(''assets/certs/client-cert1.pfx'');
    final List<int> keyBytes =
        await loadCertificate(''assets/certs/client-cert1.pfx'');
final dio dio = dio();
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
        (client) {
         final SecurityContext sc = SecurityContext()
                                  ..useCertificateChainBytes(certificateChainBytes,password: ''Secret'')
                                    ..usePrivateKeyBytes(keyBytes,password: ''Secret'');
      final HttpClient httpClient = HttpClient(context: sc);
     httpClient.badCertificateCallback =
              (X509Certificate cert,String host,int port) {
            print(''badcertificatecallback'');
            print(cert.issuer);
            return true;
          };
          return httpClient;
        };
  try {
      url = url.contains(''http'') ? url : ''${PsConfig.ps_app_url}$url'';
      print(''API Response from $url'');
      final Response response =
          await dio.get(url,options: Options(headers: getHeaders()));

      return processHttpResponse(obj,response);
    } on diolib.dioError catch (e) {
      inspect(e);
      return processdioResponse(obj,e);
    } finally {
      dio.close();
    }

我对此很陌生,但被卡住了。提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

ABP:FlurlHttpException涵盖了UserFriendlyException

ABP:FlurlHttpException涵盖了UserFriendlyException

dynamic d = ex.GetResponseJson();做到了。

谢谢

apache http客户端org.apache.http.NoHttpResponseException:目标服务器无法响应

apache http客户端org.apache.http.NoHttpResponseException:目标服务器无法响应

我正在使用apache http客户端来测试我的WS。我已经在球衣上写了一个WS。该WS的URL是

http://localhost:8080/mobilestore/rest/sysgestockmobilews/getinventory?xml=dataString

用URL调用这个WS我写了一个方法如下

public static void getInventory(String input)
        throws ClientProtocolException,IOException {

    System.out.println(input);
    String url = URL + "getinventory";
    HttpClient client = new DefaultHttpClient();

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
    nameValuePairs.add(new BasicNameValuePair("xml",input));
    String paramString = URLEncodedUtils.format(nameValuePairs,"utf-8");
    url += "?" + paramString;
    System.out.println(url);
    HttpGet request = new HttpGet(url);
    HttpResponse response = client.execute(request);
    BufferedReader rd = new BufferedReader(new InputStreamReader(response
            .getEntity().getContent()));

    String line = "";
    while ((line = rd.readLine()) != null) {
        System.out.println(line);
    }

}

现在,当我运行程序并将URL传递给此函数时,我在行中得到了异常

HttpResponse response = client.execute(request);

异常如下

Aug 14,2013 9:31:50 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing         request: The target server failed to respond
Aug 14,2013 9:31:50 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
Aug 14,2013 9:31:50 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing   request: The target server failed to respond
Aug 14,2013 9:31:50 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing      request: The target server failed to respond
Aug 14,2013 9:31:50 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
Exception in thread "main" org.apache.http.NoHttpResponseException: The target server failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:95)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:62)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:715)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:520)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at    org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
at com.tainosystems.http.client.TestWs.getInventory(TestWs.java:66)
at com.tainosystems.http.client.TestWs.main(TestWs.java:47)

现在,如果我使用WS网址并使用任何浏览器访问它,我都会得到预期的结果,但我想知道我的Apache HTTP客户端代码出了什么问题。

asp.net-mvc – HttpResponseException和HttpException之间有什么区别?

asp.net-mvc – HttpResponseException和HttpException之间有什么区别?

从 http://www.asp.net/web-api/overview/web-api-routing-and-actions/exception-handling

HttpResponseException

What happens if a Web API controller throws an exception? By default,
most exceptions are translated into an HTTP response with status code
500,Internal Server Error.

The HttpResponseException type is a special case. This exception
returns any HTTP status code that you specify in the constructor of
the exception.

除了它没有. fiddler向我显示一个500被退回.

但是,HttpException似乎做了那篇文章.

文件是错误的还是我错过了什么?

UPDATE

在打字时,我有一个想法.我试过两个控制器,一个ApiController和一个标准的MVC控制器.

这两个异常根据他们抛出的控制器的类型相互反向工作.

>使用HttpResponseException从API返回适当的HTTP代码
控制器.
>使用HttpException从一个返回一个适当的HTTP代码
MVC控制器.

解决方法

[将我的更新移至答案]

在打字时,一个ApiController和一个标准的MVC控制器.

这两个异常根据他们抛出的控制器的类型相互反向工作.

>使用HttpResponseException从API控制器返回适当的HTTP代码.>使用HttpException从MVC控制器返回适当的HTTP代码.

c# – HttpClient.SendAsync HttpException:客户端已断开连接

c# – HttpClient.SendAsync HttpException:客户端已断开连接

我有一个在 Windows Azure Web角色中托管的ASP.NET Web API应用程序.
此应用程序的目的是将Http请求代理到其他启用Web的端点(例如服务总线中继)并返回其响应.

有时,我们的应用程序在发送具有重要(> 5MB)有效负载的请求时会抛出异常.这可能发生在具有大负载的20个请求中的1个.

Exception Details: System.AggregateException: One or more errors
occurred. —> System.Web.HttpException: The client disconnected.
at System.Web.Hosting.IIS7WorkerRequest.EndRead(IAsyncResult
asyncResult) at
System.Web.HttpBufferlessInputStream.EndRead(IAsyncResult asyncResult)
at System.Net.Http.StreamToStreamcopy.BufferReadCallback(IAsyncResult
ar) — End of inner exception stack trace —
—> (Inner Exception #0) System.Web.HttpException (0x800703E3): The client disconnected. at
System.Web.Hosting.IIS7WorkerRequest.EndRead(IAsyncResult asyncResult)
at System.Web.HttpBufferlessInputStream.EndRead(IAsyncResult
asyncResult) at
System.Net.Http.StreamToStreamcopy.BufferReadCallback(IAsyncResult
ar)<— ; TraceSource ‘w3wp.exe’ event

我们使用.NET 4.5中的System.Net.HttpClient发送这些Http请求.

public class ProxyController : ApiController
{
    private static readonly HttpClient HttpClient = new HttpClient();
    private static readonly Uri BaseUri = new Uri("http://webendpoint.com");

    public HttpResponseMessage Post()
    {
        var newUri = new Uri(BaseUri,Request.RequestUri.PathAndQuery);
        var request = new HttpRequestMessage(HttpMethod.Post,newUri)
                {
                    Content = this.Request.Content
                };

        var task = HttpClient.SendAsync(request,HttpCompletionoption.ResponseHeadersRead);
        task.Wait();
        var response = task.Result;
        return new HttpResponseMessage(response.StatusCode)
        {
            Content = new PushStreamContent((stream,content,ctx) =>
            {
                var tempStream = response.Content.ReadAsstreamAsync().Result;
                tempStream.copyToAsync(stream).Wait();
                stream.Flush();
                stream.Close();
            })
        };
    }
}

有什么可能导致这个问题的想法?

解决方法

尝试返回任务版本,然后用异步替换同步代码.不再使用“.Results”内容,而是使用“await”关键字并在方法上添加“asyc”关键字.像这样的东西:

public class ProxyController : ApiController
{
    private static readonly HttpClient HttpClient = new HttpClient();
    private static readonly Uri BaseUri = new Uri("http://webendpoint.com");

    public async Task<HttpResponseMessage> Post()
    {
        var newUri = new Uri(BaseUri,newUri)
        {
            Content = Request.Content
        };

        var response = await HttpClient.SendAsync(request,HttpCompletionoption.ResponseHeadersRead);

        return new HttpResponseMessage(response.StatusCode)
        {
            Content = new PushStreamContent(async (stream,ctx) =>
            {
                var tempStream = await response.Content.ReadAsstreamAsync();
                await tempStream.copyToAsync(stream);
                stream.Flush();
                stream.Close();
            })
        };
    }
}

关于尝试使用 dio 传递客户端证书时获取空白 httpException 消息尝试使用代理是什么意思的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于ABP:FlurlHttpException涵盖了UserFriendlyException、apache http客户端org.apache.http.NoHttpResponseException:目标服务器无法响应、asp.net-mvc – HttpResponseException和HttpException之间有什么区别?、c# – HttpClient.SendAsync HttpException:客户端已断开连接等相关内容,可以在本站寻找。

本文标签: