I have one web service which accepting one parameter.
Webservice Method:
[ActionName("GetCustomers")]
[HttpPost]
[AcceptVerbs("GET","HEAD")]
public bool getcustomers(string id)
{
var result = JsonConvert.DeserializeObject<RootObject>(id.ToString());
using (System.IO.StreamWriter file = new System.IO.StreamWriter(#"D:\Result.txt"))
{
file.WriteLine(result);
}
return false;
}
if i run below url in fiddler ..GetCustomer method is invoking....
url : http://localhost:49809/Import/GetCustomers/test
if i pass with json format like in screen shot ;
my webmethod is not calling....Let me know why if pass json format it is not calling.. is is giving error :HTTP/1.1 404 Not Found
You need to change ContentType to Content-Type and remove the quotation marks around its value.
The line should read: Content-Type: application/json;charset=UTF-8
Related
I am trying to create a Mock API server using Postman. My request will have a query parameter key. I want to use the value passed to the key query parameter in the mock response.
Request: {{url}}/foo?key=3
Response:
{
"3": {
...
}
}
I tried {{url}}/foo?key={{key}}
{
"{{key}}": {
...
}
}
but that's just returning the {{key}} text as it is without any replacements. Is there any way I can use the query parameter values in the mock response?
I have an API method that needs to redirect to URL based on some input provided.
[ApiController]
public class AuthController : ControllerBase
{
[HttpGet()]
public IActionResult GetUrl(string input)
{
// retrieve a url based on the input
string url = GetUrl(input);
return Redirect(url);
}
}
When I debug this method using postman, I see that the correct URL is retrieved and the call to Redirect is made. However, in the postman, I am getting an HTTP 404 status. My questions:
How can I get some appropriate Redirect HTTP status code?
From postman, is there any way to verify if the redirect to URL was performed?
So, I'm thinking your URL that you're passing does not include http:// or https:// in front of it, and ASP.NET is trying to redirect you to http://example.com/url instead of redirecting to an external site. Try adding https:// or http:// in front of your URL that you pass to your GetUrl method. You should then get a 200 OK in Postman.
Example:
using Microsoft.AspNetCore.Mvc;
namespace WebApplication1.Controllers
{
[ApiController]
[Route("[controller]")]
public class ExampleController : ControllerBase
{
[HttpGet]
public IActionResult GetUrl([FromQuery]string url)
{
return Redirect("https://" + url);
}
}
}
In this example, if you pass url=google.com to the application, you'll get redirected to https://google.com/ and get a 200 OK in Postman.
I'm using devise on ruby on rails for authentication. Taking it one step at a time, I have disabled the cookie authentication in order to test retrieving results prior to authentication.
If I go to my browser and navigate to the url that Alamofire is visiting, I get results in JSON format like this :
{"id":250,"name":null,"username":"walker","bio":null,"gender":null,"birth_date":null,"profile_image_url":null}
I'm requesting the alamofire request like this:
Alamofire.request(requestPath, method: .get, parameters: [:], encoding: JSONEncoding.default, headers: [:]).responseJSON { (response) in
if (response.result.isFailure) {
completion(false, "")
} else {
if let result = response.result.value {
completion(true, result)
}
}
}
This is all inside of another method which simply provides with a completion handler as you can see inside of the completion handler of the Alamofire request.
I get an error every single time.
The error says:
responseSerializationFailed : ResponseSerializationFailureReason
What am i doing wrong?
This error indicates that your response is not a JSON formatted data(or something wrong with your API Response), try to use something like post man to check your API response and to make sure every thing is ok before requesting with to swift
I have just started using Postman for testing my API.
I am able to send list of request parameters, but could not figure out how will I send a parameter which is a dictionary,
say my request has two different parameters, first is property, and the structure of property is something like "ptype":"residential","mtype":"requirement","dtype":"sale","category":"multistoryapt","city":"Gurgaon,Mumbai"
How can I send these parameters together ?
I have explored on internet and there are ways of sending an array but not a dictionary.
Am I missing something ?
You could send data as raw body with the Content-Type application/json, this way it's up to you how the data is structured.
If you want to send it in the application/json format then the body should look like this:
{
"key1":"value1",
"key2":"value2"
}
For a comprehensive resource on how to serialise JSON go to http://www.newtonsoft.com/json/help/html/SerializingCollections.htm
If for some reason you cannot send it with json, here is how we send dictionaries in the form:
object[ptype], object[mtype], object[dtype], object[category], object[city]
You can do it with this:
POST Request in Postman:
Content-Type: Json/Application
{
"IsManual":true,
"platform":"IOS",
"barcodeList":{"1":"DSSDsdsdsas","2":"DSSDsdsdsas"},
"Client":"Cliente1",
"ScanDate":"2018-10-16T17:03:02.2347052-03:00"
}
I cam across this topic as I have a parameter
public Dictionary<string, string> Customer { get; set; }
for my REST API and I wanted to test it with Postman. Unfortunately I didn't find any quick help for how to send a Dictionary using Postman. After trying around some combinations this is what worked for me
Customer[0].Key:name
Customer[0].Value:Testname
Match the name of your dictionary and Request body dictionary name.
Suppose ,
Dictionary<string,string> randomName = new Dictionary<string,string(){{"key1","value1"} ,{"key2","value2"}};
so , your request for PostMan should be:
{
"randomName " : { "key1":"value1", "key2":"value2"}
}
I am currently developing a web app which should do restful service calls to existing web service api.
What I have is the base URL and the API names.
Any help on how do I start working on it?
I suppose I need to use httpbuilder for the base url I have, then followed by /api name. But how do I test it on grails if its working?
When I paste the base url on the browser it does return some xml information, so what I need is to do it on grails instead.
XML response when I paste the url through browser
<ns1:createNewUserResponse>
<userId>21</userId>
</ns1:createNewUserResponse>
So I need to be able to get this response through my web-app (grails) instead of pasting it on the browser.
EDIT*
this is a good example I found useful
#Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0-RC2' )
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
def http = new HTTPBuilder( 'http://ajax.googleapis.com' )
// perform a GET request, expecting JSON response data
http.request( GET, JSON ) {
uri.path = '/ajax/services/search/web'
uri.query = [ v:'1.0', q: 'Calvin and Hobbes' ]
headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
// response handler for a success response code:
response.success = { resp, json ->
println resp.statusLine
// parse the JSON response object:
json.responseData.results.each {
println " ${it.titleNoFormatting} : ${it.visibleUrl}"
}
}
// handler for any failure status code:
response.failure = { resp ->
println "Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"
}
}
but i do not understand the query part and how do I alter it to my need?
the URL I have contains credential of username and password, the response should return a securityToken which I need to get it out from the results. Any help would be greatly appreciated!
You can start with groovy-wslite, it provides both SOAP and REST webservice clients.
To make a call to a resfull service look at Groovy HttpBuidler - http://groovy.codehaus.org/HTTP+Builder