Web Request

This is imp code and I am sending a string of data to the agent and the agent is using HTTP.GET to my website. If I use a test string like this and send using the agent, my website can log the values 168 and 0.

local f_str = "http://www.mywebsite.com/http2.aspx?V1=168&V2=0"
agent.send(“data”,f_str);

if I make it more dynamic and add this

local f_str = “http://www.mywebsite.com/http2.aspx?V1=” + an1in + "&V2= " + an2in
agent.send(“data”,f_str);

The agent will log my request and it looks like this:

server.log(my_url);

http://www.mywebsite.com/http2.aspx?V1=168&V2=149

But my site does not respond to this request and does not log. If I copy and paste this line into Internet Explorer then the request is seen by my site. It seems the agent does not send it correctly if I have dynamically updated the request string.

Can you show us the agent code you’re using to send the http request?

I started with the Xively example so it has some leftover variable names…

`
function send_toDlog(body) {
local xively_url = “http://www.website.com/ht2.aspx?uval=1234” + body; //setup url for csv
server.log(xively_url);
//server.log(body); //pring body for testing
local req = http.get(xively_url); //add headers
local res = req.sendsync(); //send request
server.log(res.statuscode);
if(res.statuscode != 200) {
server.log("error sending message: “+res.body);
}//else device.send(“status”, (res.statuscode + " OK”)); //sends status to uart. this can be removed if not desired
}

device.on(“data”, function(feedCSV) { //take csv body in from device
//server.log(“device on”);

//send preformatted multi-ds csv
send_toDlog(feedCSV);         //send to function to call xively

});

`

local xively_url = "http://www.website.com/ht2.aspx?uval=1234" + body; //setup url for csv

should the URL in that line be: /http2.aspx…

Not sure if that’s a copy/paste error, or from your code.

What response code are you getting back?

response is 200

yes, just a mistake when I was adjusting the actual addresses for posting here. I have .aspx files capturing the query strings and can verify they work.

I can’t see anything in your code that could be causing this behaviour (assuming an1in and an2in are valid values)…

I would suggest trying to send your requests to requestbin to see what’s going on… if you want a hand with that send me a message and I’ll walk through it with you.

I did what you suggested and did some more debugging on my site. It seems I am sending 18 parameters but only the first 2 are getting to my site and the requestbin site above. Here is a complete example even though I only have the first few parameters dynamic.

Agent:
`
function send_toDlog(body) { //take in csv value
//local xively_url = “http://www.website.com/http_get3.aspx?uval=12291980” + body; //setup url for csv
local xively_url = "http://requestb.in/nikb6pni?" + body;
server.log(xively_url);
//server.log(body); //pring body for testing
local req = http.get(xively_url); //add headers
local res = req.sendsync(); //send request
server.log(res.body);
if(res.statuscode != 200) {
server.log("error sending message: “+res.body);
}//else device.send(“status”, (res.statuscode + " OK”)); //sends status to uart. this can be removed if not desired
}

device.on(“data”, function(feedCSV) { //take csv body in from device
send_toDlog(feedCSV); //send to function to call xively

});
`

IMP
`
local f_str = “&V1=” + a1str + “&V2=” + a2str + “&V3=” + t1str + “&V4=” + t2sin + “&V5=13&V6=14&V7=15&V8=16&V9=17&V10=18&V11=19&V12=20&V13=21&V14=22&V15=23&V16=24&BCE=1234”// + hardware.getimpeeid();//format("%.01f", f)
//local f_str = “&V1=” + an1in + “&V2=0&V3=0&V4=0&V5=13&V6=14&V7=15&V8=16&V9=17&V10=18&V11=19&V12=20&V13=21&V14=22&V15=23&V16=24&BCE=1234”// + hardware.getimpeeid();//format("%.01f", f)

agent.send("data",f_str);

`

I see the forum is adding the &quot where I had just quotes…???

Only uval and V1 are making it, the rest are lost.

Does a1str contain any special characters? Really you’d be better off sending a table from imp to agent, and in the agent using http.urlencode().

Peter

I can see what the server.log is printing and it all looks good. Here is a copy of the log…
http://requestb.in/nikb6pni?V1=154&V2=151&V3=75.13&V4=0.00&V5=13&V6=14&V7=15&V8=16&V9=17&V10=18&V11=19&V12=20&V13=21&V14=22&V15=23&V16=24&BCE=1234 Mon Jul 15 2013 09:32:46 GMT-0500 (Central Daylight Time): ok

Fixed by using format command
f_str = format("&V1=%d&V2=%d&V3=%.1f&V4=%.1f&V5=%.1f&V6=%.1f&V7=%.1f&V8=%.1f&V9=%.1f&V10=%.1f&V11=%.1f&V12=%.1f&V13=%.1f&V14=%.1f&V15=0&V16=0",an1f,an2f,t1f,t1max,t1min,t2f,t2max,t2min,t3f,t3max,t3min,t4f,t4max,t4min)