小编Avt*_*ili的帖子

如何进行同步或异步HTTP发布/获取

我需要Sync或Async HTTP Post/Get来从Web服务获取HTML数据.我搜索整个互联网,但我不能给出好的结果.

我试着用这个例子:

但他们没有为我工作.

HttpClient并且HttpGet是错误的,错误是:

"org.apache.http.client.HttpClient已弃用"

码:

try
{
    HttpClient client = new DefaultHttpClient();
    String getURL = "google.com";
    HttpGet get = new HttpGet(getURL);
    HttpResponse responseGet = client.execute(get);
    HttpEntity resEntityGet = responseGet.getEntity();
    if (resEntityGet != null)
    {
        //do something with the response 
    }
}
catch (Exception e)
{
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

android http

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

如何使用signalR向特定用户发送消息

我有一些signalR的问题,我无法向特定的User From Hub发送消息.

我想这样做:

public void Send(string userToId, string userForId, string message)
{

    IHubContext context = GlobalHost.ConnectionManager.GetHubContext<ChatHubs>();

    //userForId - it is Session["UserId"]
    context.Clients.User(userForId).updateMessages(message);
}
Run Code Online (Sandbox Code Playgroud)

我已经读过这个话题:http://www.asp.net/signalr/overview/guide-to-the-api/mapping-users-to-connections,但我不清楚,因为我没有这个 var name = Context.User.Identity.Name;我在我获得connectionId时,会话变量中有用户信息,第二个是当我 var myClientId = $.connection.hub.id;刷新页面或单击项目上的另一个菜单时更改了connectionId.

我有一些问题:1)我可以在没有connectionId的情况下向特定用户发送消息(仅使用session ["UserId"])吗?2)总的来说,如何使用SignalR轻松实现一对一的消息传递?

PS我正在使用ASP.NET MVC(C#)

c# asp.net-mvc messaging asp.net-mvc-4 signalr

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

标签 统计

android ×1

asp.net-mvc ×1

asp.net-mvc-4 ×1

c# ×1

http ×1

messaging ×1

signalr ×1