mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Question: Unable get response from wiremock.net server in c# #147
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Elangopalakrishnan on GitHub (Oct 16, 2018).
Hi ,
Problem:
I'm trying to implement the wiremock in c#, For that I have downloaded the wiremock .net library from NuGet,
And I'm trying to do GET method , but i'm getting below error message :(
From C#
"Id = 17, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}""
if i use "await" - It is waiting for long time then it is returning 404 file not found error,
From Post Man
Versions of packages:
WireMock.Net - 1.0.3.16
System.Net.Http - 4.3.3
Code snippet:
Please advice me what I'm missing here :(
Thanks in advance!
Elango
@StefH commented on GitHub (Oct 16, 2018):
Which Framework do you use ?
.NET 4.x.x ?
Or
.NET Core 2.x
@Elangopalakrishnan commented on GitHub (Oct 16, 2018):
Target framewok:
.NET Core 2.0
@StefH commented on GitHub (Oct 16, 2018):
WithPathinsteadWithUrlSolution:
@Elangopalakrishnan commented on GitHub (Oct 16, 2018):
hi @StefH ,
Thanks for reply, Its working fine,
For POST method , How can i check POST's response in our c# code,
like GET has - var getResp = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/product/p0001");
Can you please share the some example .json files for POST method,
It would be grateful.
Thanks!
Elango
@Elangopalakrishnan commented on GitHub (Oct 16, 2018):
Hi @StefH
I used below code, to get post's response ,
Thanks!
Elango
@Elangopalakrishnan commented on GitHub (Oct 16, 2018):
Sorry. I couldn't get you ...
Thanks & Regards
Elangopalakrishnan.V
On Oct 16, 2018 21:15, "Stef Heyenrath" notifications@github.com wrote:
@StefH commented on GitHub (Oct 16, 2018):
BTW you can use on github issues:
triple single quotes space C# (
``` c#) to start a code blockand
tripple single quotes space (
```) to end a code block@StefH commented on GitHub (Oct 16, 2018):
AH, you need a JSON mapping example.
Something like this?
@StefH commented on GitHub (Oct 16, 2018):
See also WIKI
https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching
@StefH commented on GitHub (Oct 16, 2018):
BTW you can also use the gitter channel for asking questions.
https://gitter.im/wiremock_dotnet/Lobby
@Elangopalakrishnan commented on GitHub (Oct 16, 2018):
@StefH ,
I have two .json files one is for request and one is for response,
lets say req.json and resp.json,
I'm just reading those jsons and storing in two string variables,
Then I'm just deserializing and creating objects,
and my code is,
req.json
resp.json
But i don't know , how i need to match and all, i saw above site, but i don't understand why we are using matchers.
Thanks
Elango
@StefH commented on GitHub (Oct 16, 2018):
You need to use use a matcher for the body to make sure that only a request with a specific body is matched.
So on your case you can use code like:
@Elangopalakrishnan commented on GitHub (Oct 16, 2018):
Hi , I'm using same code, and getting response like below, But i'm getting error 500.
How we can get responses ???
server
.Given(Request
.Create()
.WithPath("/jsonmatcher1")
.WithBody(new JsonMatcher("{ "Email": "myemail@gmail.com" }"))
.UsingPost())
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
.RespondWith(Response.Create().WithBody(@"{ ""isValid"": ""true"" }"));
StringContent cnent = new StringContent(JsonConvert.SerializeObject("{ "Email": "myemail@gmail.com" }"), Encoding.UTF8, "application/json");
HttpResponseMessage rponse = await new HttpClient().PostAsync("http://localhost:" + server.Ports[0] + "/jsonmatcher1", cnent);
Thanks!
Elango
@Elangopalakrishnan commented on GitHub (Oct 16, 2018):
Hi , I'm using same code, and getting response like below, But i'm getting error 500.
How we can get responses ???
server
.Given(Request
.Create()
.WithPath("/jsonmatcher1")
.WithBody(new JsonMatcher("{ "Email": "myemail@gmail.com" }"))
.UsingPost())
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
.RespondWith(Response.Create().WithBody(@"{ ""isValid"": ""true"" }"));
StringContent cnent = new StringContent(JsonConvert.SerializeObject("{ "Email": "myemail@gmail.com" }"), Encoding.UTF8, "application/json");
HttpResponseMessage rponse = await new HttpClient().PostAsync("http://localhost:" + server.Ports[0] + "/jsonmatcher1", cnent);
Thanks!
Elango
Sorry , by mistake closed :(
@Elangopalakrishnan commented on GitHub (Oct 16, 2018):
Can you please review
StringContent cnent = new StringContent(JsonConvert.SerializeObject("{ "Email": "myemail@gmail.com" }"), Encoding.UTF8, "application/json");
HttpResponseMessage rponse = await new HttpClient().PostAsync("http://localhost:" + server.Ports[0] + "/jsonmatcher1", cnent);
These codes are correct??
Thanks
Elango
@StefH commented on GitHub (Oct 16, 2018):
use