我正在尝试使用ios客户端连接到我的服务器中心。如果我使用javascript中提供的教程客户端,它可以工作。但是,为了连接到集线器,我必须使用的路径是什么。
这是客户端IOS本机代码
NSString *url = [NSString stringWithFormat:@"http://10.0.0.120:7363/ChatHub"];
SRHubConnection *hubConnection = [SRHubConnection connectionWithURL:url];
Start the connection
[hubConnection start];
这是我的服务器代码。我在OnConnected()中有一个永远不会被调用的断点。
public class ChatHub : Hub
{
public override Task OnConnected() {
return base.OnConnected();
}
}
服务器上的文件名为ChatHub,它不在任何文件夹中。我直接在项目文件下。 当我尝试运行它时,这是我的输出
线程{name =(null),num = 1}: - [SRConnection negotiate:] [第145行] [CONNECTION]将协商
我认为这与我的urlpath有关。
我收到此错误
Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: internal server error (500)" UserInfo=0x10b545230 {NSLocalizedDescription=Request failed: internal server error (500), NSErrorFailingURLKey=http://10.0.0.120:7363/signalr/signalr/negotiate?clientProtocol=1.3.0.0&connectionData=%5B%7B%22Name%22%3A%22broadcastmessage%22%7D%5D, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x10c907f50> { URL: http://10.0.0.120:7363/signalr/signalr/negotiate?clientProtocol=1.3.0.0&connectionData=%5B%7B%22Name%22%3A%22broadcastmessage%22%7D%5D } { status code: 500, headers {
"Cache-Control" = private;
"Content-Type" = "text/html; charset=utf-8";
Date = "Wed, 28 May 2014 23:09:45 GMT";
Server = "Microsoft-IIS/8.0";
"Transfer-Encoding" = Identity;
"X-AspNet-Version" = "4.0.30319";
"X-Powered-By" = "ASP.NET";
} }, NSUnderlyingError=0x10b54b550 "Request failed: unacceptable content-type: text/html"}
答案 0 :(得分:0)
我能够通过更改客户端pod规范以使用DyKnow / SignalR-ObjC'feature-2.0.0.beta1'的分支来实现此功能,然后添加一些代码以将内容类型设置为application / json for all请求以路径中的“/ signalr”开头。
class Startup
{
public void Configuration(IAppBuilder app)
{
app.Use(async (env, next) => // owin middleware
{
//set headers
env.Response.OnSendingHeaders( state =>
{
PathString pathstring = new PathString("/signalr");
if (env.Request.Path.HasValue && env.Request.Path.StartsWithSegments(pathstring))
{
var resp = (OwinResponse)state;
resp.ContentType = "application/json";
}
}, env.Response);
await next();
});
app.RunSignalR();
}
}