I created a little grpc server on my machine and Im wondering how to debug array message in browser.
Example: for one field message in gRPC with handler "/greeting" and "name" field I can request
localhost:7000/greeting?name=Slowpoke
In this way I can debug and see what really happens on my server.
How to do same moves with protobuf scheme like:
message NamesQuery {
repated string name = 1;
}
How does request in browser should look like?
By trial and error, I found the following solution for next scheme with INT fields for GET request.
message SomeNumbers {
repeated int list = 1;
}
This request:
localhost:7000/some-request?list=2&&list=12&&list=22
and I've got next message:
{"list":[2,12,22]}
Related
I'm trying to implement a callback endpoint for eBay. This endpoint is called by eBay to hand the application a user token.
I can define my endpoint as expected
http://localhost:8080/api/ebay/auth
Nothing unusual here. My enpoint looks like this, really basic:
#RestController
#RequestMapping(path = ["/api/ebay/auth"])
class EbayAuthController {
#GetMapping(path = [""])
fun getAccessToken(#RequestParam code: String) {
println("Auth code: $code")
}
}
Now eBay passes the parameter code with the value
?code=v^1.1%23i^1%23r^1%23p^3%23I^3%23f^0%23t^[excluded_user_token]&expires_in=299
When I call my endpoint with this data set, it returns 400 Bad Request. I can reproduce this by adding ^ to any request. I read it's an unsafe character to use - but the issue is: Ebay uses this character to return the user token, so I must read it.
When I pass a sample with http://localhost:8080/api/ebay/auth?code=123 it prints the code as expected.
I've never encountered that problem, can anyone help me or point me in the right direction how to solve this?
According to this answer by Dirk Deyne to the question Spring-boot controller error when url contains braces character, you can specify server.tomcat.relaxed-query-chars in your application.properties:
server.tomcat.relaxed-query-chars=^
I am using Web API calls to Dynamics 365 to get result for function QuerySchedule. I have tried using this as a bound function as well. But none of them returns the expected result. Below is documentation on this:
https://learn.microsoft.com/en-us/dynamics365/customer-engagement/web-api/queryschedule?view=dynamics-ce-odata-9
I have tried different resource id, different ways to specify the enum type in the call, fully qualified function name, etc but I always get error.
Following is my call:
https://mycrm.com/api/data/v9.0/QuerySchedule(ResourceId=#p1,Start=#p2,End=#p3,TimeCodes=#p4)?#p1=resourceguid&#p2=2019-01-05T09:27:39Z&#p3=2019-01-05T21:27:39Z&#p4=Available
The output is expected to be QueryScheduleResponse as mentioned in below link:
https://learn.microsoft.com/en-us/dynamics365/customer-engagement/web-api/queryscheduleresponse?view=dynamics-ce-odata-9
But I keep getting error message:
Object reference not set to an instance of an object.
Could anyone who has done web api calls to Dynamics 365 using OData or has any experience with this kindly help?
Quickly did a browser console test, the code snippet from this blog post works fine.
Pasting part of the snippet from the blog, your code may break as you are passing "Available" instead of ['0'] for TimeCodes.
var requestUrl = "/api/data/v9.0/QuerySchedule(ResourceId=#p1,Start=#p2,End=#p3,TimeCodes=#p4)";
requestUrl += "?#p1=" + context.getUserId().replace("{", "").replace("}", "");
//put Id of resource you want get data for as parameter 1
requestUrl += "&#p2=" + JSON.stringify(start).replace(/"/g, "");
requestUrl += "&#p3=" + JSON.stringify(end).replace(/"/g, "");
requestUrl += "&#p4=" + JSON.stringify(['0']);
Even you can paste this url in your browser address bar to smart test:
Request:
https://test.crm.dynamics.com/api/data/v9.0/QuerySchedule(ResourceId=#p1,Start=#p2,End=#p3,TimeCodes=#p4)?#p1=0EEE678F-C4FF-E711-A959-000D3A1A941E&#p2=2019-01-15T09:27:39Z&#p3=2019-01-15T21:27:39Z&#p4=['0']
You may notice ['0'] turn into [%270%27] but the below expected response will appear.
Response:
{"#odata.context":"https://test.crm.dynamics.com/api/data/v9.0/$metadata#Microsoft.Dynamics.CRM.QueryScheduleResponse","TimeInfos":[{"Start":"2019-01-15T00:00:00Z","End":"2019-01-16T00:00:00Z","TimeCode":"Available","SubCode":"Schedulable","SourceId":"15f40c32-1609-46db-93da-1bbb8eb19c9d","CalendarId":"69b0ee2b-bad7-4b8e-9bcc-d03e76b45a03","SourceTypeCode":4004,"IsActivity":false,"ActivityStatusCode":-1,"Effort":1.0,"DisplayText":""}]}
I am using MetaTrader4.Manager.Wrapper
I want to get all currency (Symbol in MT4) and their bid & ask from MT4. I tried using :
public IList<Symbol> Get()
{
using (var metatrader = new ClrWrapper(new ConnectionParameters
{
Login = serverdata.Login,
Password = serverdata.Password,
Server = serverdata.Server
}, serverdata.path))
{
var Refresh = metatrader.SymbolsRefresh();
IList<Symbol> Live = metatrader.SymbolsGetAll();
return Live;
}
}
From the code i got the Name : AUDCAD, AUDCHF, EURCHF, etc, but BidTickValue and AskTickValue return 0.0.
I tried using this answer but the Symbol return null and Bid return 0.
Is there another way to get the Name and Bid and Ask value?
And what is Pumping Mode means?
Thank you before
Pumping is MT4 mode, when you subscribe to different events and MT4 server sends you updates, without requesting it manually.
For example: quotes, trades, users.
SymbolsGetAll will return you quotes only when you in pumping mode, and it will return latest received quote.
If you are not going to use pumping mode, you can get latest quote user ChartRequest method, but it will be much slower.
You can get the quotes with bid and ask directly without manager API.
Simply you can send a socket to MT4 server.
Here is an example:
// 1. Start Session.
$ptr=fsockopen('127.0.0.1',443);
// error check
if (!$ptr){
echo "Connection error";
exit;
}
// 2. Send request to MT4
fputs($ptr,"WQUOTES-EURUSD,GBPUSD,USDJPY,\nQUIT\n");
// 3. Reading and processing server responses
while(!feof($ptr))
{
// read line of symbols
$line=fgets($ptr,128);
// the symbol of the end of result transfer
if($line=="end\r\n") break;
// process
print $line;
}
// 4. Session completion
fclose($ptr);
The above will print the quotes in this format: direction symbol bid ask date time.
I am using goRequest http://parnurzeal.github.io/gorequest/ to make some HTTP requests against a server process I need to talk to. The authentication process works like this;
send in a GET request with an authentication header set. No problem there, but I need to grab a header from the response and use a returned value to reauthenticate each following request.
The retuned HTTP header looks like this.
Response headers
map[Location:[900767244] Content-Type:[application/xml] Date:[Fri, 18 Sep 2015 18:19:41 GMT] Server:[Apache] X-Frame-Options:[SAMEORIGIN] Set-Cookie:[JSESSIONID=D5C976F5646365FF030DBAD770DA774C; Path=/; Secure; HttpOnly]]
I need to get that location value as it's my session token going forward. If I grap it like this:
session, ok := response.Header["Location"]
if !ok {
fmt.Println("Did not receive a location header.")
}
fmt.Println("Session: ", session)
I can get it, but it's a slice and NOT a string. How can I get that value as a string so I can pop it back into my request headers going forward? As you can see in the following error:
./login.go:133: cannot use session (type []string) as type string in argument to logoutRequest.Delete
Thanks a lot!
Craig
If you want one value, use the Header's Get method
location := response.Header.Get("Location")
This also canonicalizes the header name for you, so that you still get a value even when using slightly different capitalization.
You only need to index an http.Header value directly when you need to get more than than the first possible value. If you want all values with a canonicalized header name, you can use textproto.CanonicalMIMEHeaderKey
vals := response.Header[textproto.CanonicalMIMEHeaderKey(header)]
The headers have location as an array, you just need to pass Location[0] to that method rather than simply Location because it is a slice. That being said, indexing into the array without checking the bounds is unsafe so you should probably do;
if len(Location) == 1 {
logoutRequest(Location[0])
} else {
// error state
}
One last thing to provide you guidance in the future. You can tell that the response headers object has a type more like this; map[string][]string (in reality that maybe []interface{} but I'm not certain from the output) by seeing that each item inside the outer brackets [] has it's values contained within another set of brackets, meaning it is an array that could contain 0 or more values.
Hi I am downloading file from server. I have to take meta-information using HEAD method. andybody help me to implement the HEAD method to get "last-modified" date and modified-since date.
here is my code:
HttpClient client= new DefaultHttpClient();
//HttpGet get = new HttpGet(url);
HttpHead method = new HttpHead(url);
HttpResponse response= client.execute(method);
Header[] s=response.getAllHeaders();
System.out.println("THe header from the httpclient:");
for(int i=0; i < s.length; i++){
Header hd = s[i];
System.out.println("Header Name: "+hd.getName()
+ " " + " Header Value: " + hd.getValue());
}
//here I have to implement the HEAD method
The difference between a HEAD and a GET method is that the response will not contain a body. Otherwise, the two are the same. In other words, a HEAD method gets all the headers. It is not used for getting data of a single header, it just retrieves all headers at once.
In the code example you already have all headers, because you executed a HEAD request. In the for-loop you output all data from the headers. If the last-modified is not there, the server did not provide it for this resource.
Note that the if-modified-since is a request header field, not a response header field. You can set it to instruct the server to only return the resource if the modified-since date has passed. If you intend to only retrieve a resource when it has been modified on the server, you can just use a GET request with the if-modified-since header set. To know whether a server supports this header, check this tool: http://www.feedthebot.com/tools/if-modified/