Forum Discussion
problems with POST call on REST API
- 4 years ago
Hi Anonymous
Try explicitly using HTTPS, your query currently is not.
https://localhost:5000/v1/api/iserver/secdef/searchRegards
Phil
Apart from the the missing accept header it looks benign. Care to try adding that?
- Anonymous4 years agoNot applicable
Hi and thanks.
Can you point me to a resource which may explain that to me, or suggest how the syntax looks ?
there's nothing to drill down into at MS in this link: https://docs.microsoft.com/en-us/powerquery-m/web-contents.
In the other examples I got working, there wasn't anything that resembled an inbound header (or the like).
Cheers
Rohan
- lbendlin4 years ago
Super User
headers = [#"Content-Type" = "application/json", Accept = "application/json"]
- Anonymous4 years agoNot applicable
Hi
Thanks for the efforts to help find a solution. I made many minor changes to the code in the path to find a solution, and it seems the solution was to amend "http://" to "https://". I commend the code below as the "solution" (which includes a few comments which are redundant trials, as well as some shaping to visually show me some results), and I thank all who helped.
let
url = "https://localhost:5000/v1/api/iserver/secdef/search",
//cookiestr = "get the value of bm_sv cookie from browser",
headers = [#"Content-Type" = "application/json; charset=uts-8"], //, accept = "application/json"], //, Cookie = cookiestr],
query= Json.FromValue(
[
symbol = "BHP",
name = true,
secType = "STK"
]),
body = Json.FromValue(
//body = Text.ToBinary(
[
symbol = "BHP",
name = true,
secType = "STK"
//exchange = "ASX"
]
),
//Content = Text.ToBinary(body),
//add error capture "try"
//handle it down the track
response = try Web.Contents(
url,
[
//RelativePath = "iserver/secdef/search",
Headers = headers,
Content = body
//Query = query
]
),
// Content = Text.ToBinary(body),
// add error capture "try"
// handle it down the track
Value = response[Value],
#"Imported JSON" = Json.Document(Value,65001),
#"Converted to Table" = Table.FromList(#"Imported JSON", Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"conid", "companyHeader", "companyName", "symbol", "description", "restricted", "fop", "opt", "war", "sections"}, {"Column1.conid", "Column1.companyHeader", "Column1.companyName", "Column1.symbol", "Column1.description", "Column1.restricted", "Column1.fop", "Column1.opt", "Column1.war", "Column1.sections"})
in
#"Expanded Column1"thanks again.
RT
- Anonymous4 years agoNot applicable
Hi
I have placed a support call to the data provider. However they do not support nor comment on Power query (or end user platforms generally). So no success there at present.
I ran the diagnostics and got the following in hte detailed PQ analytics. What I note is that the Json record for headers and content is not displayed, and outside of creating another step to interrigate these records (which I have done and it looks fine), they don't appear in the results of the diagnostics. See below:
Request:
POST http://localhost:5000/v1/api/iserver/secdef/search HTTP/1.1
<Headers placeholder>
<Content placeholder>
Response:
<Content placeholder>The exception raised is below (but outside of my skills to understand, troubleshoot, diagnose)
Exception:
ExceptionType: System.Net.WebException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxx
Message: The underlying connection was closed: The connection was closed unexpectedly.
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.Mashup.Engine1.Library.Http.WrappingHttpWebRequest.<>c__DisplayClass119_0.<WrapResponse>b__0()
at Microsoft.Mashup.Engine1.Library.Http.WrappingHttpWebRequest.WrapExceptionResponse[T](Func`1 getValue)
at Microsoft.Mashup.Engine1.Library.Http.WebRequestFactory.TlsSniffingWebRequest.GetResponse()
at Microsoft.Mashup.Engine1.Library.Http.Request.CreateResponse(ResourceCredentialCollection credentials)
at Microsoft.Mashup.Engine1.Library.Http.Request.GetResponseCore(ResourceCredentialCollection credentials)
at Microsoft.Mashup.Engine1.Library.Http.RetryPolicy.Execute[TResult](IEngineHost host, Func`1 func)
at Microsoft.Mashup.Engine1.Library.Http.Request.GetResponse(ResourceCredentialCollection credentials, RetryPolicy retryPolicy, SecurityExceptionCreator securityExceptionCreator, Boolean tokenRefreshed)
I am running out of any angles I can change my review/solution hunting.
Are there ways to catch the error (try... otherwise ...? ), and perhaps review more detail (or is the detail posted above all of what comes from the server that I am hitting?). I haven't any other ways that I am aware of in hitting the server to apply a POST (query ?) with the field/Value pairs ?
Kind regards
Rohan