servicestack,webclient,C#,servicestack,Webclient" /> servicestack,webclient,C#,servicestack,Webclient" />

C# webClient.UploadValues(URLAuth,“POST”,formData);在登录我的restservice站点之前,我需要先登录

C# webClient.UploadValues(URLAuth,“POST”,formData);在登录我的restservice站点之前,我需要先登录,c#,servicestack,webclient,C#,servicestack,Webclient,嗨,我可以用这个代码登录这个网站,我只能写这个代码 这可以登录并获取我的Json;; //我很高兴你帮我拿了json。谢谢serviceStack。 //但你对我来说太复杂了。我不明白你的意思 public static string ServStack_basicAuth(string baseUri) { var client = new JsonServiceClient(baseUri); client.SetCredentials("admin", "admin");

嗨,我可以用这个代码登录这个网站,我只能写这个代码

这可以登录并获取我的Json;; //我很高兴你帮我拿了json。谢谢serviceStack。 //但你对我来说太复杂了。我不明白你的意思

public static string ServStack_basicAuth(string baseUri)
{
   var client = new JsonServiceClient(baseUri);
   client.SetCredentials("admin", "admin");
   client.AlwaysSendBasicAuthHeader = true;   //only work when this is true

   var request = client.Get<string>(baseUri);
}
谢谢大家。。。 我可以在serviceStack中执行此操作吗? 我可以做什么/读什么来理解servicestack代码? 必须使用此servicestack吗?或任何好的简单的其他方式??
我迷路了。。谢谢你

有些人说不要使用webclient??如果你不了解ServiceStack,你应该努力完成入门。
//this is .nets webclient 
//but this cant login, thus cant post my values to form.

string URLAuth = "http://site.herokuapp.com/mts400resultses";
WebClient webClient = new WebClient();

NameValueCollection formData = new NameValueCollection();
formData["j_username"] = "admin";   //  j_username  and j_password html input's name
formData["j_password"] = "admin";

byte[] responseBytes = webClient.UploadValues(URLAuth, "POST", formData);
string resultAuthTicket = Encoding.UTF8.GetString(responseBytes);