本文整理汇总了C#中JsonServiceClient.Post方法的典型用法代码示例。如果您正苦于以下问题:C# JsonServiceClient.Post方法的具体用法?C# JsonServiceClient.Post怎么用?C# JsonServiceClient.Post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonServiceClient
的用法示例。
在下文中一共展示了JsonServiceClient.Post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunTests
public void RunTests()
{
string username = "passuser";
string passHash = MD5Helper.CalculateMD5Hash("password");
JsonServiceClient client = new JsonServiceClient(SystemConstants.WebServiceBaseURL);
Login(client, username, passHash);
client.Get<XamarinEvolveSSLibrary.UserResponse>("User");
Logout(client);
client.Get<XamarinEvolveSSLibrary.UserResponse>("User");
Login(client, username, passHash);
User user = new User()
{
UserName = username,
City = "changedtown",
Email = "[email protected]"
};
client.Post<XamarinEvolveSSLibrary.UserResponse>("User", user);
Logout(client);
client.Post<XamarinEvolveSSLibrary.UserResponse>("User", user);
}
示例2: AddLargeImage
public static void AddLargeImage(JsonServiceClient client)
{
Console.WriteLine("Getting image");
var fp = client.Post(new FloorPlanRequestDto.FloorplanAdd {BluePrintId = 1, Floor = RandomGenerator.Integer(10000), FloorDesc = "1"});
Console.WriteLine(string.Format("Added image id is {0}", fp.Id));
var image = Image.FromFile(LargeImageLocation);
string base64 = Convert.ToBase64String(image.ImageToByteArray());
Console.WriteLine("Sending image...");
var resp = client.Post(new FloorPlanRequestDto.FloorplanAddImage {FloorplanId = fp.Id, Image = base64});
Console.WriteLine("Message: {0}\nMessage: {1}\nResponse Status: {2}", resp.Result, resp.Message, resp.ResponseStatus);
Console.ReadLine();
}
示例3: Test_GET_two_PASS
public void Test_GET_two_PASS()
{
var restClient = new JsonServiceClient(serviceUrl);
var newemp1 = new Employee() { Id = 1, Name = "Joe", StartDate = new DateTime(2015, 1, 2), };
var newemp2 = new Employee() { Id = 2, Name = "Julie", StartDate = new DateTime(2012, 12, 2), };
restClient.Post<object>("/employees", newemp1);
restClient.Post<object>("/employees", newemp2);
var emps = restClient.Get<List<Employee>>("/employees");
Assert.NotNull(emps);
Assert.NotEmpty(emps);
Assert.Equal(2, emps.Count);
}
示例4: Main
private static void Main()
{
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
// PerformanceTest();
var client = new JsonServiceClient(Settings.Default.ServiceAddress);
var createRequest = new CreateClientRequest
{
Email = "[email protected]"
};
var response = client.Post<ClientResponse>(createRequest);
Console.WriteLine("POST Response: {0}\n", response);
var updateRequest = new UpdateClientRequest
{
Email = "[email protected]",
Id = response.Id
};
response = client.Put<ClientResponse>(updateRequest);
Console.WriteLine("PUT Response: {0}\n", response);
var getClientRequest = new GetClientRequest
{
Id = response.Id,
Date = DateTime.Now.Date
};
response = client.Get<ClientResponse>(getClientRequest);
Console.WriteLine("GET Response: {0}\n", response);
var deleteRequest = new DeleteClientRequest
{
Id = response.Id
};
client.Delete(deleteRequest);
var certificate = new MemoryStream(File.ReadAllBytes("Certificate.cer"));
var uploadRequest = new UploadRequest
{
FileContents = certificate.ToArray(),
OriginalFileName = "MyFileName.cert",
UploaderId = Guid.NewGuid().ToString()
};
client.Post(uploadRequest);
Console.ReadKey();
}
示例5: getBuild
/// <summary>
/// Get a new build
/// </summary>
/// <returns>BuildInfo object or null on error/no build</returns>
public static BuildInfo getBuild()
{
Console.WriteLine("* Checking for builds...");
var client = new JsonServiceClient (apiurl);
try
{
var buildInfo = client.Post (new CheckForBuild
{
token = Uri.EscapeDataString (Config.token)
});
if (buildInfo != null)
{
return buildInfo;
}
}
catch (WebServiceException ex)
{
if(ex.StatusCode == 404)
{
Console.WriteLine ("* Nothing");
}
else
{
Console.WriteLine ("* Failed");
}
}
return null;
}
示例6: Populate
public void Populate()
{
////var svc = new KnockKnockMongo();
//var db = svc.Database<PotatoKnock>();
//db.DeleteMany(Builders<PotatoKnock>.Filter.Empty);
var knock = new KnockDto {
FeedId = Guid.NewGuid(),
Id = Guid.NewGuid(),
Location = new LocationDto
{
Latitude = 45,
Longitude = 60
},
Message = "Turn me into a french fry?"
};
using (var svc = new JsonServiceClient("http://localhost:40300/"))
{
var knockstr = knock.SerializeToString();
svc.Post(new KnockPost { Knock = knock });
}
//svc.Any(new KnockPost {Knock = knock});
Console.WriteLine(knock.Id);
}
示例7: TryLogin
public void TryLogin()
{
using(var tempDb = new TempFile())
{
//GlobalProxySelection.Select = new WebProxy("127.0.0.1", 8888); // proxy via Fiddler2.
using (var server = new Server() { Port = 8000, SqliteFile = tempDb.Path })
{
server.Start();
// log in
var restClient = new JsonServiceClient(FakeServer.BaseUri);
var response = restClient.Post<AuthResponseEx>(
"/api/auth/credentials?format=json",
new Auth()
{
UserName = "tech",
Password = "radar",
RememberMe = true
});
response.SessionId.ShouldMatch(@"[a-zA-Z0-9=+/]{20,100}");
response.UserName.ShouldBe("tech");
response.UserId.ShouldMatch(@"^[a-zA-Z0-9_-]{8}$");
// log out
var logoutResponse = restClient.Delete<AuthResponse>("/api/auth/credentials?format=json&UserName=tech");
logoutResponse.SessionId.ShouldBe(null);
// can't come up with a good way to verify that we logged out.
}
}
}
示例8: CreateApp
public static void CreateApp(string endpoint, string appName)
{
JsonServiceClient client = new JsonServiceClient(endpoint);
client.Post(new Server.CreateAppRequest()
{
AppName = appName
});
try
{
Server.CreateAppStatus status;
do
{
status = client.Get(new Server.CreateAppStatusRequest() { AppName = appName });
if (status == null) break;
Console.Write(status.Log);
Thread.Sleep(200);
}
while (!status.Completed);
}
catch (WebServiceException e)
{
Console.WriteLine(e.ResponseBody);
Console.WriteLine(e.ErrorMessage);
Console.WriteLine(e.ServerStackTrace);
}
}
示例9: OnTestFixtureSetUp
public void OnTestFixtureSetUp()
{
Client = new JsonServiceClient(BaseUri);
var response = Client.Post<AuthenticateResponse>("/auth",
new Authenticate { UserName = "test1", Password = "test1" });
}
示例10: Test_PostWithBadHostnameAndGetMessage_StatusIsFailed
public void Test_PostWithBadHostnameAndGetMessage_StatusIsFailed()
{
// Create message
var postRequest = new CreateMessage
{
ApplicationId = 1,
Bcc = new[] { "[email protected]" },
Body = "This is a test email.",
Cc = new[] { "[email protected]" },
Connection = new Connection
{
EnableSsl = false,
Host = "nonexistant",
Port = 25
},
Credential = new Credential(),
From = "[email protected]",
ReplyTo = new[] { "[email protected]" },
Sender = "[email protected]",
Subject = "Test Message",
To = new[] { "[email protected]" }
};
var client = new JsonServiceClient("http://localhost:59200/");
var postResponse = client.Post(postRequest);
// Get message
var getRequest = new GetMessage
{
Id = postResponse.Id
};
var getResponse = client.Get(getRequest);
Assert.Equal(3, getResponse.Status.TypeMessageStatusId);
Assert.Equal(postResponse.Id, getResponse.Id);
}
示例11: RunTests
public void RunTests()
{
byte[] imageData;
using (Image srcImage = Image.FromFile(@"D:\Bill\Code\XamarinEvolve2013Project\TestSSAPI\testavatar.jpg"))
{
using (MemoryStream m = new MemoryStream())
{
srcImage.Save(m, ImageFormat.Jpeg);
imageData = m.ToArray(); //buffers
}
}
JsonServiceClient client = new JsonServiceClient(SystemConstants.WebServiceBaseURL);
UserAvatar userAvatar = new UserAvatar()
{
UserName = "billholmes",
Data = imageData,
};
UserAvatarResponse response = client.Post<UserAvatarResponse>("UserAvatar", userAvatar);
//response = client.Delete<UserAvatarResponse>("UserAvatar/billholmes");
return;
}
示例12: registerRunner
/// <summary>
/// Register the runner with the coordinator
/// </summary>
/// <param name="sPubKey">SSH Public Key</param>
/// <param name="sToken">Token</param>
/// <returns>Token</returns>
public static string registerRunner(String sPubKey, String sToken)
{
var client = new JsonServiceClient (apiurl);
try
{
var authToken = client.Post (new RegisterRunner
{
token = Uri.EscapeDataString (sToken),
public_key = Uri.EscapeDataString (sPubKey)
});
if (!authToken.token.IsNullOrEmpty ())
{
Console.WriteLine ("Runner registered with id {0}", authToken.id);
return authToken.token;
}
else
{
return null;
}
}
catch(WebException ex)
{
Console.WriteLine ("Error while registering runner :", ex.Message);
return null;
}
}
示例13: CanPerform_PartialUpdate
public void CanPerform_PartialUpdate()
{
var client = new JsonServiceClient("http://localhost:53990/api/");
// back date for readability
var created = DateTime.Now.AddHours(-2);
// Create a record so we can patch it
var league = new League() {Name = "BEFORE", Abbreviation = "BEFORE", DateUpdated = created, DateCreated = created};
var newLeague = client.Post<League>(league);
// Update Name and DateUpdated fields. Notice I don't want to update DateCreatedField.
// I also added a fake field to show it does not cause any errors
var updated = DateTime.Now;
newLeague.Name = "AFTER";
newLeague.Abbreviation = "AFTER"; // setting to after but it should not get updated
newLeague.DateUpdated = updated;
client.Patch<League>("http://localhost:53990/api/leagues/" + newLeague.Id + "?fields=Name,DateUpdated,thisFieldDoesNotExist", newLeague);
var updatedLeague = client.Get<League>(newLeague);
Assert.AreEqual(updatedLeague.Name, "AFTER");
Assert.AreEqual(updatedLeague.Abbreviation, "BEFORE");
Assert.AreEqual(updatedLeague.DateUpdated.ToString(), updated.ToString(), "update fields don't match");
Assert.AreEqual(updatedLeague.DateCreated.ToString(), created.ToString(), "created fields don't match");
// double check
Assert.AreNotEqual(updatedLeague.DateCreated, updatedLeague.DateUpdated);
}
示例14: check_secured_post_requires_credentials
public void check_secured_post_requires_credentials()
{
var restClient = new JsonServiceClient(WebServerUrl);
var request = new Secured { Data = "Bob" };
var error = Assert.Throws<WebServiceException>(() => restClient.Post<SecuredResponse>("/Secured/", request));
Assert.AreEqual("Unauthorized", error.Message);
Assert.AreEqual((int)HttpStatusCode.Unauthorized, error.StatusCode);
}
示例15: btnCreate_Click
private void btnCreate_Click(object sender, EventArgs e)
{
AdventureType type = new AdventureType() { Name = txtName.Text };
ServiceClientBase client = new JsonServiceClient("http://localhost:10768");
var response = client.Post<AdventureType>("/Adventure/Types/", (AdventureType)type);
}