标签: http-error

J2ME上的httpconnection和Android上的HttpUrlConnection有什么区别(http error 401)

我在我的应用程序上连接到两台服务器(PROD是https,测试服务器是http).

在J2ME上:我可以毫无问题地连接到这两台服务器.在Android上我无法连接到测试服务器.当连接是http时,如果我不使用setChunkedStreamingMode,我不能得到,responseCode(StringIndexOutOfBoundsException);如果我使用setChunkedStreamingMode,响应代码是401.我该怎么办,我的错在哪里?

这是我的android代码,如果你想看J2me代码,我也可以添加它.

URL url = new URL(getUrl());
            URLConnection conn = url.openConnection();
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setAllowUserInteraction(false);
            httpConn.setInstanceFollowRedirects(true);
            httpConn.setConnectTimeout(10000);
            httpConn.setRequestProperty("User-Agent", util.getDeviceFullModel()
                    + " " + util.getSoftwareVersion());
            httpConn.setRequestProperty("Accept-Charset", "utf-8");

            httpConn.setRequestProperty("Content-Type",
                    "text/xml; charset=utf-8");
            httpConn.setRequestProperty("SOAPAction",
                    "http://tempuri.org/IAuthenticationServiceForGroup/"+conTypeString);
            httpConn.setRequestProperty("Software-Version", AppData.VERSION);
            httpConn.setChunkedStreamingMode(getParams().getBytes("UTF8").length);
            httpConn.setRequestMethod("POST");
            httpConn.setDoOutput(true);
            httpConn.setDoInput(true);
            httpConn.connect();

            os = httpConn.getOutputStream();
            os.write(getParams().getBytes("UTF8"));

            try {
                os.close();
            } catch (Exception e) {
                onError(e);
            }
            response=httpConn.getResponseCode();
Run Code Online (Sandbox Code Playgroud)

J2ME代码:

HttpConnection c = (HttpConnection)XConnection.openConnection(XConnection.SERVER + "AuthenticationServiceForGroup.svc");

            c.setRequestProperty("User-Agent", XUtil.getDeviceFullModel() + " " + XUtil.getSoftwareVersion());
            c.setRequestProperty("Content-Type", "text/xml; …
Run Code Online (Sandbox Code Playgroud)

android httpurlconnection http-error java-me

6
推荐指数
1
解决办法
1734
查看次数

ASP.NET Web API从响应中删除HttpError

我正在使用Microsoft ASP.NET Web API构建RESTful服务.

我的问题涉及Web API在出现问题时返回给用户的HttpErrors(例如400 Bad Request或404 Not Found).

问题是,我不希望得到系列化HttpError响应内容,因为它有时会提供太多的信息,因此它违反了OWASP安全规则,例如:

请求:

http://localhost/Service/api/something/555555555555555555555555555555555555555555555555555555555555555555555
Run Code Online (Sandbox Code Playgroud)

作为回复,我当然得到400,但有以下内容信息:

{
 "$id": "1",
 "Message": "The request is invalid.",
 "MessageDetail": "The parameters dictionary contains a null entry for parameter 'id'  of non-nullable type 'System.Int32' for method 'MyNamespaceAndMethodHere(Int32)' in 'Service.Controllers.MyController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."
}
Run Code Online (Sandbox Code Playgroud)

这样的事情不仅表明我的WebService基于ASP.NET WebAPI技术(也不是那么糟糕),而且还提供了有关我的命名空间,方法名称,参数等的一些信息.

我试图在Global.asax中设置IncludeErrorDetailPolicy

GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Never;
Run Code Online (Sandbox Code Playgroud)

是的,这确实很好,现在结果不包含MessageDetail部分,但仍然,我根本不想得到这个HttpError.

我还构建了自定义DelegatingHandler,但它也影响了我自己在控制器中生成的400和404,我不想发生这种情况.

我的问题是:是否有任何方便的方法来摆脱响应内容中的序列化HttpError?所有我希望用户回复他的错误请求是响应代码.

asp.net response http-error asp.net-web-api

6
推荐指数
1
解决办法
1208
查看次数

ASP.Net 请求引发 502 Bad Gateway 或 TimeOut

我有一个在 IIS7 上运行的 C# ASP.NET Webforms 网站。它是一个报告创建应用程序,用于查询 SQL Server 数据库、获取数据并将其解析为 Excel 文档。

查询本身不会花费太长时间,但当查询非常大(50,000 行)时,写入 Excel 需要一段时间。

现在的问题是,当我运行报告应用程序时,我会在几分钟内收到报告,但是当某些用户运行它时,报告会返回 502 Bad Gateway。这只发生在大型报告中。

我认为这与超时有关?即使我更改哪个超时命令,网关错误也会在两分钟内出现。

c# asp.net iis http-error

6
推荐指数
2
解决办法
1万
查看次数

HttpResponse(status=<code>) 在 Django 中如何工作?

我正在 django 中试验 HTTP 错误代码,所以我有一个关于HttpResponse(status=<code>). 比如我想发送一个HTTP错误代码405,我有如下代码:

def myview(request):
   if request.method == 'POST':
      ...
   else:
      return HttpResponse(status=405)
Run Code Online (Sandbox Code Playgroud)

我也有这个 HTTP 错误代码(405.html)的模板,我把下面的代码行放在 urls.py 中

handler405 = 'handling_error.views.bad_method'
Run Code Online (Sandbox Code Playgroud)

我的 bad_method 视图如下:

def bad_method(request):
    datos_template = {}
    return render(request, '405.html', datos_template, status=405)
Run Code Online (Sandbox Code Playgroud)

我以为这样Django会根据HTTP错误代码重定向到正确的模板,但它不起作用,然后:

我做错了什么吗?HttpResponse(status=) 在 Django 中如何工作?通过 HttpResponse(status=) 发送 HTTP 错误代码的目的是什么?

对不起,很多问题:P

我希望有一个人可以帮助我。

python django http-error

6
推荐指数
1
解决办法
7023
查看次数

Http请求状态码405 ReasonPhrase:''Youtube APi

我尝试发送这两个请求,但我只得到标题中列出的错误作为响应.我对谷歌服务器的两个网络请求是这样的:

HttpClient http = new HttpClient();

HttpResponseMessage response = await http.GetAsync("https://accounts.google.com/o/oauth2/token?code="+localSettings.Values["AccessKey"]+"&client_id=XX-XXXXXXXXXX.apps.googleusercontent.com&client_secret=XXXXX-XXXX&redirect_uri=http://localhost/oauth2callback&grant_type=authorization_code");

//response.EnsureSuccessStatusCode();
Debug.WriteLine(response.ToString());
HttpResponseMessage response1 = await http.GetAsync("https://content.googleapis.com/youtube/v3/subscriptions?part=id&maxResults=10&mine=true&key="+localSettings.Values["AccessKey"]);
Debug.WriteLine(response1.ToString());
Run Code Online (Sandbox Code Playgroud)

我从调试器获得以下输出:

StatusCode: 405, ReasonPhrase: '', Version: 2.0, Content: System.Net.Http.StreamContent, Headers:
{
  server: GSE
  alt-svc: quic=":443"; p="1"; ma=604800
  cache-control: max-age=0, private
  accept-ranges: none
  date: Tue, 29 Sep 2015 16:05:03 GMT
  x-frame-options: SAMEORIGIN
  vary: Accept-Encoding
  x-content-type-options: nosniff
  alternate-protocol: 443:quic,p=1
  x-xss-protection: 1; mode=block
  content-type: application/json
  expires: Tue, 29 Sep 2015 16:05:03 GMT
}
StatusCode: 400, ReasonPhrase: '', Version: 2.0, Content: System.Net.Http.StreamContent, Headers:
{
  server: …
Run Code Online (Sandbox Code Playgroud)

c# api response httprequest http-error

6
推荐指数
1
解决办法
836
查看次数

无法使用 Webview android 获取 HTTP 401 错误的回调

我正在使用带有 WebViewClient 的 Webview 来加载需要身份验证的 URL。我正在使用WebViewClient 的onReceivedHttpAuthRequest方法为每个请求设置身份验证。

@Override
    public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
        handler.proceed("username", "password");
    }
Run Code Online (Sandbox Code Playgroud)

这适用于只需要基本身份验证的 URL。

但是,我的应用程序中的某些 URL 需要使用请求中的一些额外标头进行登录访问。所以对于这种请求,基本的认证是不够的,服务器会抛出 401 auth 错误。

因此,对于这种情况,我需要捕获 401 错误并需要将用户导航到登录屏幕。从棉花糖开始,WebViewClient 提供了以下方法来处理此类 HTTP 错误。

    @Override
    public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
        super.onReceivedHttpError(view, request, errorResponse);
        if(errorResponse.getStatusCode() ==401){
            // Code to navigate user to Login Screen.
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是我没有找到任何可以处理或获取此类 401 错误回调的棉花糖设备。此外,回调方法onReceivedError也不起作用。

任何帮助,将不胜感激。

android http-error android-webview webviewclient

6
推荐指数
0
解决办法
1070
查看次数

烧瓶“get_or_404”类似功能,但有另一个状态码

我知道的:

我们都知道,flask 有一个有用的功能,query.get_or_404我们可以将它调用到任何类对象并返回该对象,或者如果找不到该对象则引发 404 错误。

问题:

我有一个非常大的应用程序并使用该函数进行查询,但是当我将数据发送到前端和其他使用我的 API 的应用程序时,它现在变得有点混乱。当未找到他们查询的对象时,它将返回 404,并且在未找到页面时也会发生相同的行为。

我想要达到的目标:

我想要一个有意义的响应,对于每个未找到的对象都是不同的,对于正常的 404 错误消息是不同的。

例子 :

如果我有这个查询:

user = User.query.get_or_404(id)

如果找不到用户,我想引发 HTTP 错误并返回类似的消息 user not found

到目前为止我尝试过的:

    user = User.query.get(id)
    if user:
        #do something
    else 
        return {'status':'01', 'description': 'user not found'} 
        # or raise a http error 
Run Code Online (Sandbox Code Playgroud)

这种方法的问题是我无法维护我正在处理的应用程序,它需要我在使用 get_or_404 和该代码的任何地方进行更改。

我在想什么:

创建一个类似query.get_or_404但带有另一个状态消息的函数query.get_or_415,例如,并为 415 HTTP 代码添加一个错误处理程序,以便如果找不到对象,它可以返回{'status':'0message:ge : 'object of the class is not found'}

我怎样才能实现它?

我已经在 Flask 中检查过该功能,但找不到它

有人有建议吗?

python sqlalchemy http-error flask flask-sqlalchemy

6
推荐指数
2
解决办法
1万
查看次数

尝试将 Base64 图像绘制到画布时出现 HTTP 错误 431

我尝试在客户端 JavaScript 中将图像(base64 格式)绘制到画布上。不幸的是总是有ERR_CONNECTION_RESET 431 (Request Header Fields Too Large)错误。

我将 Base64 图像作为对节点服务器的异步 POST 请求的响应。Base64 图像示例如下:

'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCA==='
Run Code Online (Sandbox Code Playgroud)

但显然更长。Chrome 开发控制台显示如下:

GET http://localhost:3000/'data:image/png;base64,iVBORw0KGgoAA...
net::ERR_CONNECTION_RESET 431 (Request Header Fields Too Large)
Image (async)
(anonymous) @ client.js:59
async function (async)
(anonymous) @ client.js:51
Run Code Online (Sandbox Code Playgroud)

我的代码是:

'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCA==='
Run Code Online (Sandbox Code Playgroud)

其中canvas_ctx是画布的 2d 上下文,base64_response是上述指定格式的图像。

我还应该提到,我是 JavaScript 和 Web 开发的新手,因为我只为我的一个项目这样做。

javascript base64 client-side http-error

6
推荐指数
1
解决办法
1万
查看次数

错误的请求。您的浏览器发送了此服务器无法理解的请求。请求标头字段缺少':'分隔符

我正在编写HTTP代理应用程序的Java代码。在该浏览器中,请求未正确发送,因此服务器正在响应

错误的请求您的浏览器发送了此服务器无法理解的请求。请求标头字段缺少':'分隔符。我不明白为什么会发生错误。

我是java的新手,所以可以知道此问题的解决方案。

请求消息:

GET / HTTP/1.1<br>Host: www.google.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Run Code Online (Sandbox Code Playgroud)

我的请求中有错误,但我无法确定。

所以任何人都可以帮助我解决我的问题。

java sockets proxy bad-request http-error

5
推荐指数
0
解决办法
1940
查看次数

Retrofit / RxJava-获取http响应代码

Android,翻新,RxJava。请查看以下示例调用:

 mcityService.signOut(signOutRequest)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(resp ->
                {
                    busyIndicator.dismiss();
                    finish();
                }, throwable ->
                {
                    Log.d(tag, throwable.toString());
                    busyIndicator.dismiss();
                    Toast.makeText(this,throwable.getMessage(),Toast.LENGTH_LONG).show();
                    finish();
                });
Run Code Online (Sandbox Code Playgroud)

有人知道如何从throwable获取错误代码(作为错误号)吗?我能够获取完整的stacktrace或消息(如上所示)。如何捕获错误代码?

来自throwable的错误代码: 在此处输入图片说明

android http-error retrofit2 rx-java2

5
推荐指数
1
解决办法
2967
查看次数