I'm having trouble using the poDoNotEncode option in the TRESTRequest.AddParameter() method. I need to be able to post a request with a j_token header with a value that includes the '/' characters or else. For this need, I read everywhere that I can simply add poDoNotEncode to the options of the request parameters.
I tried several methods I found on the Internet to add a j_token header to my request:
var
RESTRequest : TRESTRequest;
RESTClient : TRESTClient;
Response : TRESTResponse;
begin
RESTClient := TRESTClient.Create('http://127.0.0.1:5000/')
RESTRequest := TRESTRequest.Create(nil);
try
RESTRequest.Client := RESTClient;
RESTRequest.Method := rmPOST;
RESTRequest.AddParameter('j_token', 'ga/ga', pkHTTPHEADER, poDoNotEncode);
//RESTRequest.Params.AddHeader('j_token', 'ga/ga').Options := poDoNotEncode;
//RESTRequest.Params.AddItem('j_token', 'ga/ga', pkHTTPHEADER, poDoNotEncode);
RESTRequest.Execute;
Response := RESTRequest.Response;
ShowMessage(Response.Content);
finally
RESTClient.Free;
RESTRequest.Free;
end;
end;
In this example, I used my own API to see the content of my request headers (here just j_token). Each and every method I tried (the commented ones) result with this:
Request headers : ga%2Fga
Meaning that the header I'm sending is url-encoded whether or not poDoNotEncode is specified.
Just to clarify, I'm working currently on a program developed by the company I work for. This software should use Delphi 10.3 Rio as its script language.
Maybe it can help, but when I try something like this:
RESTRequest.AddParameter('j_token', 'ga/ga', pkHTTPHEADER, [poDoNotEncode]);
I get this error:
RUNTIME ERROR : Impossible converting variant of type (Array Variant) to type (Integer) when evaluating instruction PushVar($0,$0,$0,$0, 'Result')...
And when I try something like this:
RESTRequest.AddParameter('j_token', 'ga/ga', pkHTTPHEADER, TRESTRequestParameterOptions.poDoNotEncode);
then I get this error:
Unknown identifier or variable is not declared : 'TRESTRequestParameterOptions'
I tried to be as precise as possible, because I'm completely stuck right now. If you need more precision, I'll try to answer as clearly as possible.
I've solved my problem. To provide a context, I have access to the archives of my company with every script they made. To learn delphi it helps a lot, and as I was looking at an example for the TRESTRequest.AddParameter() method i noticed that the 4th parameter for this method was a 0 like this :
RESTRequest.AddParameter('j_token',mytoken,pkHTTPHEADER,0);
So I looked on the internet to find what that 0 meant and i found out it was supposed to be an option for the parameter such as poDoNotEncode. I was still wondering why they replaced that with a 0 but I simply guessed it was to avoid an error if you don't put anything because our compiler wants the RESTRequest.AddParameter() method to have 4 parameters. So in the end i started doing the same until i needed my parameter to not getting encoded. But the poDoNotEncode option wasn't working. I tried to see what it would show inside a ShowMessage(poDoNotEncode); and it showed me a 0. So I decided as a test to put a 1 instead of poDoNotEncode like this :
RESTRequest.AddParameter('j_token',mytoken,pkHTTPHEADER,1);
And finally it worked, I have no idea why our software prefers using Integers instead of the real options names but if ever you stumble upon this problem, there is a high chance that you had the same weird definition of options.
Thank you all for your help !
Related
Running "CODESYS V3.5 SP16" here, does anyone have the same problem with the method in the title?
PROGRAM PLC_PRG
VAR
itfAxisRef : SM3_Basic.IAxisRef;
pAxisRefSm3 : POINTER TO SM3_Basic.AXIS_REF_SM3;
END_VAR
pAxisRefSm3 := itfAxisRef.GetAxisRefPointer;
Trying to compile the above throws the following error
C0032: Cannot convert type 'GETAXISREFPOINTER(sm3_basic, 4.10.0.0 (3s - smart software solutions gmbh))' to type 'POINTER TO SM3_Basic.AXIS_REF_SM3'
which has me really confused because I've never seen the type GETAXISREFPOINTER before and the documentation for .GetAxisRefPointer states that it returns POINTER TO AXIS_REF_SM3
https://help.codesys.com/webapp/3dvrBKsuKjYfmeP1KzrJnylfstc%2FGetAxisRefPointer;product=SM3_Basic;version=4.9.0.0
As for why I'm trying to use this method, I'm trying to loop through the array of axes in SM3_Robotics.AXIS_GROUP_REF_SM3 and pass them to SM3_Basic.MC_ReadStatus in order to get their individual SM3_Basic.SMC_AXIS_STATE (not only the SM3_Robotics.SMC_AXIS_GROUP_STATE) for debugging
Is there a better way to achieve the above without using the axes array?
GetAxisRefPointer is a Method, try:
pAxisRefSm3 := itfAxisRef.GetAxisRefPointer();
recently I stumbled upon one of the videos of Benjamin Schumann titled: What are dynamic and action parameters and when should you use them in your AnyLogic model.
I tried to further adjust the functions of dynamic and action based parameters for a problem of mine. Just to give a heads up, I am fairly new to Anylogic (only worked through that one book, and some minor projects and tutorials) and been decent in Java (been a few years since I've been actively working in Java but currentlystarting to get back in [still rusty]).
Regarding my actual problem, in the video Mr. Schumann has an agent with three parameters. One static, one dynamic and one action. In addition to that he has a variable (double) all set in his agent. On his main is a button to increment the value of the variable with the help of the parameters and to trace the lines in the console (= giving out a string if a certain threshold of the variable is passed).
I created a similar setting, however I happen to run into a lot of variable errors during time to time while compiling.
Here some example code snippets:
dynamic parameter p_Station of the type String
v_myFahrt < 222 ? "Wiesbaden Hbf" :
v_myFahrt < 442 ? "Wiesbaden-Biebrich Bahnhof Wiesbaden Ost" :
v_myFahrt < 663 ? "Wiesbaden-Mainz-Kastel Bahnhof" :
"Hochheim (Main) Bahnhof"
therefore my variable is called v_myFahrt, a double with the initial value of 0
action parameter p_durchFahrt with the default action:
v_myFahrt = v_myFahrt + 220;
and my Button on the main:
myAgent.p_durchFahrt();
traceln(myAgent.p_Station());
So basically it is a somewhat similar code as in the reference. I tried to than add another instance of the agent with a different set of "code" for the dynamic parameter (different Strings and values) as well as a different "code" for the action parameter (e.g. + 208 instead of + 220). To then wanting to trace the lines in the console with the button again.
I tried to add
myAgent1.p_durchFahrt(); traceln(myAgent1.p_Station());
to it.
But before I coul even run it, I keep getting the error "v_myFahrt cannot be resolved to a variable" for myAgent1. Inspecting the error it keeps referring to myAgent1 with the newly added code for p_Station and I can't seem to find a way around it.
What am I doing majorly wrong here?
it looks like you have created v_myFahrt in main, right? (that would explain your symptoms).
If yes, you should create it in MyAgent instead.
I'm learning Chrome Postman now and my issue now is:
I need to generate a new value of a parameter for each request.
So each request (I make a POST) must have a unique value of this parameter.
So far I thought to manage it with environment variables and I have done it like this:
I add a new environment variable with a unique value
I use this variable in the "value" field on a parameter
And it doesn't work - I get error 401 Authorization Required.
Seems that the error is not connected to the parameter at all but as soon as I change the parameter and manually input a unique data it works well!
So this will work for me:
Please suggest what I'm doing wrong here and advice how to do it right. Thanks!
Spent some more hours investigating I found my problem!
The problem is the value I put into a variable - it included ":" sign and this sign simply changed my URL.
I have this kind of request which seems to be GWT-RPC format :
R7~"61~com.foo.Service~"14~MethodA~D2~"3~F7e~"3~B0e~Ecom.foo.data.BeanType~I116~Lcom.foo.Parameter~I5~"1~b~Z0~"1~n~V~"1~o~Z1~"1~p~Z1~"1~q~V~'
But it is not in line with protocol described here:
https://docs.google.com/document/d/1eG0YocsYYbNAtivkLtcaiEE5IOF5u4LUol8-LL0TIKU/edit
What exactly is this protocol ? Is it really GWT-RPC or something else (deRPC?) ?
Looking into gwt-2.5.1 source code, I notice it seems that following packages could be generating this kind of format:
com.google.gwt.rpc.client
com.google.gwt.rpc.server
Is this deRPC ?
Based on a quick glance through the deRPC classes in the packages you listed, it does indeed appear to be deRPC. Note that deRPC has always been marked as experimental, and is now deprecated, and that either RPC or RequestFactory should be used instead.
Details that seem to confirm this:
com.google.gwt.rpc.client.impl.SimplePayloadSink#RPC_SEPARATOR_CHAR is a constant equal to the ~ character, which appears to be a separator between different tokens in the sample string you provided.
Both com.google.gwt.rpc.client.impl.SimplePayloadSink andcom.google.gwt.rpc.server.SimplePayloadDecoder` have many comments that appear to depict the same basic format that you are seeing in there:
// "4~abcd in endVisit(StringValueCommand x, Context ctx) closely matches several tokens in the sample string - a quote indicating a string, an int describing the length, a ~ separator, then the string itself (this doesnt match everything, I suspect because you removed details about the service and the name of the method):
"3~F7e
"3~B0e
"1~b
Booleans all follow Z1 or Z0, as in your sample string
I'm currently working on benchmarking a RESTful service I've made, and part of that is making sure it runs in a reasonable amount of times for a large array of parameters. For example, let's say I have RESTful API of the form some_site.com/item?item_id=y. In that case to be sure my service is working as fast as I'd like it to work, I'd want to try out many values for y one by one, preferably coming from some text file. I can't figure out any way of doing this in ab or httperf. I'm open to using a different benchmarking program if I have, but would prefer something simple and light. What I want to do seems like something pretty standard, so I'm guessing there must already be a program that let's me do it, but an hour or so of googling hasn't gotten me an answer. Ideas?
Answer: Jmeter (which is apparently awesome). This faq explains how to do it. Hopefully this helps someone else, as it took me like a day of searching to figure this out.
I have just had some good experience with using JavaScript (via BSF/Rhino) in JMeter.
I have put one thread group in my test plan and stick a 'Simple Controller' with two elements under it - 'HTTP Request' sampler and 'BSF PreProcessor'.
Set BSF language to 'javascript' and either type the code into the text box or point it to a file (use full path or relative to CWD of JMeter process).
/* Since `Math.random()` gives us float, we use `java.util.Random()`
* see: http://docs.oracle.com/javase/7/docs/api/java/util/Random.html */
var Random = new Packages.java.util.Random();
var min = 10-1;
var max = 2;
var maxLines = (min)+Random.nextInt(max-min);
var s = '';
for (var d = 0; d <= maxLines; d++) {
s += d.toString()+','+Random.nextInt(1000).toString()+'\n';
}
// s => '0,312\n1,104\n2,608\n'
vars.put('PAYLOAD', s);
Now I can refer to ${PAYLOAD} in the HTTP request!
You can generate JSON, but you will need to upgrade jakarta-jmeter-2.5.1/lib/js-1.6R5.jar with the newest version of Rhino to get JSON.stringify and JSON.parse. That worked perfectly for me also, though I thought I'd put a simple example here.
You can use BSF pre-processor for URL params as well, just set another variable with vars.put('X', 'some value') and pass it as ${X} in the request parameter.
This blog post helped quite a bit, by the way.