标签: response

RESTful API响应状态代码消除歧义

我正在开发一个RESTful API,并对某些场景中最合适的响应状态代码提出疑问.

考虑客户端对资源发出GET请求的情况.对于资源合法不存在的情况,如何可能存在轻微的服务中断(在部署期间等),我如何消除"未找到"响应的歧义.

rest web-services http response http-status-codes

4
推荐指数
2
解决办法
1709
查看次数

在Java中,如何设置Restlet响应的头?

我似乎无法弄清楚如何将标头添加到我的restlet响应中.当我看到在可用的方法Response的对象,我看到的是setStatus,setEntitysetAttributes但这些都不告诉我如何设置自定义HTTP头的响应.

例如,我有一个GET调用返回类似如下的内容:

HTTP/1.1 200 OK
Content-Type: text/json
Content-Length: 123
Some-Header: the value
Some-Other-Header: another value

{
  id: 111,
  value: "some value this could be anything",
  diagnosis: {
    start: 12552255,
    end: 12552261,
    key: "ABC123E11",
    source: "S1",
  }
}
Run Code Online (Sandbox Code Playgroud)

不管它是什么.在handleGet方法中,我这样处理它:

final MediaType textJsonType = new MediaType("text/json");

@Override
public void handleGet() {
  log.debug("Handling GET...");
  final Response res = this.getResponse();

  try {
    final MyObject doc = this.getObj("hello", 1, "ABC123E11", "S1");
    final String …
Run Code Online (Sandbox Code Playgroud)

java response restlet http-headers

4
推荐指数
1
解决办法
7657
查看次数

如何摆脱Rails中响应头的charset

我正在尝试制作一个文件下载控制器,但不幸的是rails似乎一直在弯曲,不让我从标题中删除字符集

Content-Type:application/x-octet-stream; 字符集= utf-8的

我尝试过after_filter,headers ['Content-Type'],response.headers ['Content-Type']等,但没有用.UTF-8不断涌现.任何想法为什么会发生以及如何摆脱它?

ruby-on-rails header response

4
推荐指数
1
解决办法
555
查看次数

由Response.Redirect引起的System.Threading.ThreadAbortException

在我的应用程序中,我从JavaScript调用WebMethod,我试图重定向到某个页面:

[WebMethod]
public string Logout() {            
    if (User.Identity.IsAuthenticated) {                            
        HttpContext.Current.Response.Redirect("~/Pages/Logout.aspx");               
    }
    return "";
}
Run Code Online (Sandbox Code Playgroud)

aspx页面:

    <input onclick="callLogout();" id="btn" type="button" value="Click Me" />

    <asp:ScriptManager ID="ScriptManager" runat="server">
        <Services>
            <asp:ServiceReference Path="~/WebServices/EMSWebService.asmx" />
        </Services>
    </asp:ScriptManager>
    <script type="text/javascript">        
        function callLogout() {
            EMSApplication.Web.WebServices.EMSWebService.Logout(OnComplete, OnError);
        }

        function OnComplete(result) {
            alert(result);
        }

        function OnError(result) {
            alert(result.get_message());
        }
    </script>
Run Code Online (Sandbox Code Playgroud)

我得到了:

mscorlib.dll中出现'System.Threading.ThreadAbortException'类型的第一次机会异常

mscorlib.dll中出现"System.Threading.ThreadAbortException"类型的异常,但未在用户代码中处理

在我的VS2010的输出窗口中.

为什么我会收到此异常,如何解决此问题?

c# asp.net exception response webmethod

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

Node.Js/Express - 简单的中间件,输出前几个响应字符

对于日志记录/调试,我想在发送到浏览器之前输出响应的前100个字符左右.我可以用中间件和响应对象做一些简单的事情吗?

理想情况下它是这样的:

app.use(function(req, res, next) {
    console.log('Response snippet: '+((res.body || '').substr(0,100)));
    next();
});
Run Code Online (Sandbox Code Playgroud)

除了响应没有正文,我无法弄清楚当前正在发回的主体在哪里通过.

更新:

彼得的回答有效,我想我会把我的中间件代码放在这里,以便为未来的观众点击一下:

App.use(function(req, res, next) {
    var end = res.end;
    res.end = function(chunk, encoding){
        res.end = end;
        if (chunk) {
            console.log(chunk);
        }
        res.end(chunk, encoding);
    };
    next();
});
Run Code Online (Sandbox Code Playgroud)

middleware response node.js express

4
推荐指数
1
解决办法
2944
查看次数

iphone延迟了服务器的响应

一旦我向服务器发送请求(通过NSURLConnection sendSynchronousRequest方法),服务器在大约2秒钟内收到请求,它会在另外3-5秒内处理并发回响应.但是,我只能在30-35秒内收到回复.这种延迟使我们的沟通非常缓慢.

即使是异步API也会得到延迟响应.

早些时候,一切都运行正常,客户在10秒内收到回复.还有谁有相同的问题吗?可能是什么原因?

编辑 这里是Wireshark分析的截图:

链接到更好的图像

在此输入图像描述

我怎么能看到什么包说什么?..为什么它会被推迟?

EDIT2 这是代码:

 NSHTTPURLResponse *response=nil;

NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:nsURL] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:180.0];
[theRequest setHTTPMethod:@"POST"];
[theRequest setTimeoutInterval:180.0];
[theRequest setHTTPBody:[[NSString stringWithFormat:@"%@",sdata] dataUsingEncoding:NSASCIIStringEncoding]];

NSError *error= nil;

NSData *result = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
if (error ) {
    NSLog(@"error sending synchronous request: %@", error);
}
NSLog(@"request completed with code:%d",response.statusCode);
Run Code Online (Sandbox Code Playgroud)

iphone response request nsurlconnection ios

4
推荐指数
1
解决办法
4212
查看次数

如何在"laravel"中设置没有响应的cookie

我想用这组路线完成所有东西之后设置cookie但是当我使用"过滤前"时,它会返回一个响应,然后停止做另一件事.

我该怎么办?

这是我的代码

Route::filter('setcookie',function() {

    $test = Input::get('test',0);
    $cookie = Cookie::forever('cookie',Input::get('test'));     

    return Response::make(View::make('pages.home'))->withCookie($cookie);
});
Run Code Online (Sandbox Code Playgroud)
Route::group(array('before' => 'setcookie'),function() 
{
    Route::get('/', function() {
        return View::make('pages.home');
    });

    Route::controller('productrest', 'ProductRestController');
    Route::resource('product', 'ProductController');
});
Run Code Online (Sandbox Code Playgroud)

cookies response laravel

4
推荐指数
1
解决办法
6929
查看次数

WSO2 ESB跟踪请求 - 响应

我正在研究WSO2 ESB 4.8.1

ESB HOME/repository/logs/wso2carbon.log
Run Code Online (Sandbox Code Playgroud)

我需要知道一个请求与其通过我的代理服务的相对响应之间的连接.

我尝试遵循在我的代理的insequence和out序列中打印的MessageID属性,但我意识到,即使我不太确定,这个属性是不同的.

那么我怎么知道所有响应都与哪些请求相关联?

我应该创建自己的自定义属性并将其记录在序列和后序中吗?

logging response wso2 request wso2esb

4
推荐指数
1
解决办法
1809
查看次数

如何在C++中使用Curl获取HTTP响应字符串

我是HTTP命令和libcurl库的新手.我知道如何获取HTTP响应代码而不是HTTP响应字符串.以下是我为获取响应代码而编写的代码片段.有关如何获取响应字符串的任何帮助将非常感谢!

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
CURLcode ret = curl_easy_perform(curl);

if (ret != CURLE_OK) {
    LOG(INFO) << "Failed to perform the request. "
              << "Return code: " << ret;
    return false;
}

std::unique_ptr<int64_t> httpCode(new int64_t);
// Get the last response code.
ret = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, httpCode.get());
if (ret != CURLE_OK) {
  LOG(INFO) << "curl_easy_getinfo failed to retrieve http code. "
            << "Return code: " << ret;
  return false;
}
Run Code Online (Sandbox Code Playgroud)

我尝试这样做以获取readBuffer中的HTTP响应字符串.

static size_t WriteCallback(char *contents, size_t size, size_t nmemb, void *userp)
{
    ((std::string*)userp)->append((char*)contents, …
Run Code Online (Sandbox Code Playgroud)

c++ string curl http response

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

在Yii2控制器中返回json的正确方法

我一直在寻找互联网上的答案,并与我的合作伙伴进行了讨论,但仍不确定在yii2控制器中返回json的最佳选择。这里的选项:

public function actionExample (){//1
    // do something whit $data result ...
    \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
    return $data;
}


public function actionExample (){//2
    // do something whit $data result ...
     echo json_encode($data);

    Yii::$app->end();
}
Run Code Online (Sandbox Code Playgroud)

我认为第一个选择是RESTful控制器的最佳选择(更优雅)。但是,如果无法确定对控制器的所有调用是否都可以接收json,或者如果某些调用是异步的,则第二个选项可能是最好的选择,则应停止ejecution。希望有人能解释一下每种方法的优缺点

php json controller response yii2

4
推荐指数
1
解决办法
1198
查看次数