400 Error when sending GET request to server using AT commands - html

so I'm trying to use and Arduino Due and a SIM7600 LTE Shield to send a GET request to a server. I've tried multiple servers to no avail and I'm not really sure what I'm doing wrong. Below are my AT commands
19:34:00.607 -> AT+CHTTPACT="website.co.uk",80
19:34:00.710 -> +CHTTPACT: REQUEST
19:34:07.533 -> GET website.co.uk/4gtest.php HTTP/1.0
19:34:12.302 -> Host: website.co.uk
19:34:19.101 -> Content-Length: 42
19:34:28.000 ->
19:34:28.000 -> OK
And below is the response:
19:34:28.581 -> +CHTTPACT: DATA,295
19:34:28.581 -> http/1.1 400 bad request
19:34:28.581 -> server: nginx
19:34:28.581 -> date: tue, 04 feb 2020 19:34:27 gmt
19:34:28.581 -> content-type: text/html
19:34:28.581 -> content-length: 150
19:34:28.581 -> connection: close
19:34:28.581 ->
19:34:28.581 -> <html>
19:34:28.581 -> <head><title>400 Bad Request</title></head>
19:34:28.615 -> <body>
19:34:28.615 -> <center><h1>400 Bad Request</h1></center>
19:34:28.615 -> <hr><center>nginx</center>
19:34:28.615 -> </body>
19:34:28.615 -> </html>
19:34:28.648 ->
19:34:28.648 -> +CHTTPACT: 0
There is definitely an internet connection as it returns custom error pages from the servers but I'm not sure why it can't get the pages I want.
Any help would really be appreciated
Thanks

I've been able to get a server response with the following request:
GET /4gtest.php HTTP/1.1<CR><LF>
Host: website.co.ukCR><LF>
<CR><LF>
<CR><LF>
I got Error 404 response, probably because it was a test page that had currently been removed. Anyway it is not Error 400 response meaning that, at least, the request is not malformed.
Some description about the request:
After GET command, only the path is expected (as correctly suggested by user #juraj's comment)
Since your error response specified HTTP/1.1, I used the same version for my request
The hostname is passed in the line Host: website.co.uk
Please note that each line is terminated with the <CR> + <LF> couple of characters (carriage return, 0x13 ASCII, and line feed, 0x10 ASCII). It is important to specify it because in your question it is not clear how the lines are terminated
Also note that after the last line a double <CR> + <LF> couple terminates the header section of the request
About Content-Length
I have omitted Content-Length field in my request. As brilliantly explained in the answers to this question, this field specifies the number of octects contained in the message body, after the header. But:
The AT command log in your question did not mention any body after the header
As explained in this answer, request bodies in GET requests are not explicitely forbidden, but they are not recommended
Yes, you can send a request body with GET but it should not have any
meaning. If you give it meaning by parsing it on the server and
changing your response based on its contents, then you are ignoring
this recommendation in the HTTP/1.1 spec, section 4.3

Related

TCL/Expect encoding

I have an el5 system with "tcl" and "expect", intended use for use Asterisk Call Manager / 1.0, I make a telnet connection to send messages (use of VGSMII, with vgsm_sms_tx command).
When I actually make the connection in telnet and write the commands, and the text of the messages, no problem. Instead when I do it to the script, Asterisk Call Manager is unable to send messages with special characters (example: € èé)
The O.system uses en_US.utf-8 as the encoding.
TCL should use iso-8859 (if I'm not wrong).
I tried to set up
set var1 [encoding convertto utf-8 $var0]
but nothing seems to change...
I also tried with the gsm0338
Thanks
Normally, you'd want the same encoding to be used by Tcl and by the far end program that you're using at the moment; it's pretty rare for other programs in-between (such as ssh or telnet) to do much other than carry the majority of bytes through unchanged. If the other side expects to be UTF-8, Tcl should be told to use UTF-8 on that channel. In theory, you can put the channel into binary mode and use encoding convertto utf-8 to generate the bytes to write… but that's horrible and easy to get wrong so it should be avoided when you're not doing something complicated.
It's not very well documented, but Expect's spawn IDs are (a special type of) Tcl channels. That means you can, after the spawn, do this once:
# Assuming you're not in a procedure; use $::spawn_id otherwise
fconfigure $spawn_id -encoding utf-8
and everything should Just Work™ from there on.
In the end, i convert only the messages in base64, with this works fine.
i follow this(in view mode, doesn't view anything):
http://open.voismart.it/index.php?title=VGSM_Manager_Interface&action=edit
=vgsm_sms_tx Action=
The vGSM Asterisk's channel driver provides a manager action to send Short Messages (SMS). The action is named '''vgsm_sms_tx'''.
If the message does not contain characters in the [http://www.dreamfabric.com/sms/default_alphabet.html GSM default alphabet] the message will be sent with UCS2 but the available characters will be reduced to 80.
In pre-0.21.0 releases the action was named '''VGSMsmstx'''. This name is now deprecated and vgsm_sms_tx will be supported starting from 0.21.0.
== Parameters ==
{| class="wikitable"
!Header
!Usage
!Description
|-
|'''To'''
|Mandatory
|The phone number to which to send the SMS. It may be in national format (347123456) or international format (+39347123456). The 00 or other operator-specific prefixes are not supported.
|-
|'''X-SMS-ME'''
|Optional
|Specifies the interface on which the SMS is sent. If not specified the SMS is sent on the first available interface. Huntgroups are supported using the <tt>huntgroup:name</tt> syntax, but sending will not currently be retried if there is a failure on the chosen module. Also, only sequential hunting is supported.
|-
|'''X-SMS-SMCC-Number'''
|Optional
|If present, forces the use of a specific Service Center.
|-
|'''X-SMS-Reject-Duplicates'''
|Optional
|Maps to TP-Reject-Duplicates (TP-RD), Ref. TS 100 901, §9.2.3.27
|-
|'''X-SMS-Reply-Path'''
|Optional
|Maps to TP-Reply-Path (TP-RP), Ref. TS 100 901, §9.2.3.17
|-
|'''X-SMS-Status-Report-Request'''
|Optional
|Maps to TP-Status-Report-Request (TP-SRR), Ref. TS 100 901, §9.2.3.5
|-
|'''X-SMS-Message-Reference'''
|Optional
|Maps to TP-Message-Reference (TP-MR), Ref. TS 100 901, §9.2.3.6
|-
|'''X-SMS-Validity-Period'''
|Optional
|Maps to TP-Validity-Period (TP-VP), Ref. TS 100 901, §9.2.3.12, specifies for how much time (in seconds, starting from now) the SMS message is valid and delivery should be attempted. If not specified the default value is 4 days.
|-
|'''X-SMS-Class'''
|Optional
|If specified sets the SMS class. Class 0 is used for flash SMSes, class 3 is used for normal messages. The use of other classes has to be evaluated.
|-
|'''X-SMS-Concatenate-RefID'''
|Optional
|In UDH Concatenate IE, specifies the Reference Id of the split message
|-
|'''X-SMS-Concatenate-Total-Messages'''
|Optional
|In UDH Concatenate IE, specifies the number of messages in which the main message is split
|-
|'''X-SMS-Concatenate-Sequence-Number'''
|Optional
|In UDH Concatenate IE, specifies the sequence number of this messages
|-
|'''Content-Type'''
|Optional
|Defines the content type; Only ''text/plain'' is currently supported
|-
|'''Content-Transfer-Encoding'''
|Optional
|Defines the content encoding, valid values are:
* ''7bit'': 7-bit ASCII text
* ''hex'': Hex-Encoded text
* ''base64'': Base64-encoded text
* ''quoted-printable'': Quoted-printable escaping
|-
|'''Content'''
'''Content2'''
'''ContentN'''
|Mandatory
|The SMS body in the encoding specified in the Content-Transfer-Encoding or 7-bit ASCII if that header is missing.
|-
|}
''IMPORTANT'': Asterisk Manager Interface does NOT support line lengths greater that 80 characters, including the header name, thus, it is mandatory to split the '''Content''' header in more headers with at most 65 characters each, unfortunately the splitting is supported starting from vstuff 1.0.0 which is not yet released. Please use a snapshot in the meantime.
''FIXME!!'' This statement needs to be confirmed. Asterisk version 1.4.14 allows a message of 160 char in one single Content: line. Will a message of size > 160 trigger more than 1 SMS?
===Response statuses===
=====Success=====
* 201 Message Sent
=====Temporary failures =====
* 400 Network out of order
* 401 Module is not ready
* 402 Module is not registered
* 403 Module is already sending a message
* 404 Cannot find an available module
* 405 Cannot allocate message
* 406 Out of memory
=====Permanent failures=====
* 501 Cannot find module
* 502 Services Center number not set
* 503 Cannot open iconv context
* 504 Invalid Content-Type
* 505 Unsupported content-Type
* 506 Unsupported Content-Transfer-Encoding
* 507 Charset conversion error
* 508 Cannot find huntgroup
* 509 Content: header missing
* 510 To: header missing
* 511 Message too big
* 512 Unspecified message preparation error
== Example of a SMS sending session ==
===Authentication===
[root#voismart-4-000000 chan_vgsm]# telnet localhost 5038
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
Asterisk Call Manager/1.0
Action: login
Username: sms
Secret: sms
Response: Success
Message: Authentication accepted
===Simple ASCII message===
Action: vgsm_sms_tx
To: +393471234567
Content-type: text/plain; charset=ASCII
Content: Ciao, questo e' un SMS. Niente caratteri 8-bit, qui.
Status: 201
X-SMS-Reference: 22
Response: Success
Message: Message sent
===UTF-8 encoded message with characters in the GSM alphabet===
Action: vgsm_sms_tx
To: +393471234567
X-SMS-ME: vodafone
X-SMS-Class: 3
X-SMS-SMCC-Number: +393492000200
Content-type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64
Content: VGVzdCBVVEYtOCBlbmNvZGluZyB3aXRoIGNoYXJhY3RlcnMgaW4gdGhlIEdTTSBhbHBoY
Content2: WJldC4gQWNjZW50czogw6DDqMOsw7LDuSwgR3JlZWsgTGV0dGVyczogzqbOk86bzqnOo
Content3: M6ozqPOmM6eLCBPdGhlcjogwqXCo8OHw5jDuMOFw6XigqzDhsOmw5/DicKkCg==
===UTF-8 encoded message with characters outside the GSM alphabet===
Action: vgsm_sms_tx
To: +393471234567
X-SMS-ME: vodafone
X-SMS-Class: 3
X-SMS-SMCC-Number: +393492000200
Content-type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64
Content: Q2hhcnMgb3V0c2lkZSBHU00gY2hhcnNldC4gQXJhYjog27Hbstuz27Tbtdu227fbuNu5L
Content2: CBIZWI6INeQ15HXkteT15TXldeW15fXmNeZCg==
===Concatenated messages===
Action: vgsm_sms_tx
To: +393471234567
X-SMS-ME: vodafone
X-SMS-Concatenate-RefID: 58
X-SMS-Concatenate-Total-Messages: 2
X-SMS-Concatenate-Sequence-Number: 1
Content-type: text/plain; charset=ASCII
Content: This is message part 1 of 2, that will be followed by part 2 of 2 which
Content2: will be sent later.
Action: vgsm_sms_tx
To: +393471234567
X-SMS-ME: vodafone
X-SMS-Concatenate-RefID: 58
X-SMS-Concatenate-Total-Messages: 2
X-SMS-Concatenate-Sequence-Number: 2
Content-type: text/plain; charset=ASCII
Content: This is part 2 of 2, the message is now complete. We can thus send up
Content2: to 255 parts for a total of 40,800 charaters (for just 38 Euros!)
===Sending message using a huntgroup===
Action: vgsm_sms_tx
To: +34600123456
X-SMS-ME: huntgroup:safaricom
Content-type: text/plain; charset=ASCII
Content: This message is sent using one of the several ME in the group safaricom
=vgsm_sms_rx Event=
On reception of an inbound SMS (SMS-DELIVERY) the message will also be reported as a manager event, however, acknowledgment still relies on SMS spooler to handle the message. This event is generated starting from 0.21.0
Here follows an example of a received SMS via the manager interface:
Event: vgsm_sms_rx
Privilege: call,all
Received: from GSM module vodafone2, registered on 22210 (Vodafone, Italy); Wed, 20 Jun 2007 19:40:14 +0200
From: <+393471234567#sms.voismart.it>
Subject: SMS message
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: base64
Date: Wed, 20 Jun 2007 19:39:25 +0200
X-SMS-Message-Type: SMS-DELIVER
X-SMS-Sender-NP: ISDN telephony
X-SMS-Sender-TON: International
X-SMS-Sender-Number: +393471234567
X-SMS-SMCC-NP: ISDN telephony
X-SMS-SMCC-TON: International
X-SMS-SMCC-Number: +393492000429
X-SMS-More-Messages-To-Send: yes
X-SMS-Reply-Path: no
X-SMS-User-Data-Header-Indicator: no
X-SMS-Status-Report-Indication: no
Content: SG8gY2hpYW1hdG8gYWxsZSAxOTozOSBkZWwgMjAvMDYvMDcuIEluZm9ybWF6aW9uZSBncmF0dWl0YSBkZWwgc2Vydml6aW8gQ0hJQU1BTUkgZGkgVm9kYWZvbmUu
=vgsm_me_state Event=
Whenever a ME (GSM module) changes working state, an event is generated. Here is an example of such type of events:
Event: vgsm_me_state
Privilege: call,all
X-vGSM-ME-State: POWERING_OFF
X-vGSM-ME-Old-State: READY
X-vGSM-ME-State-Change-Reason: Asterisk shutdown
The currently implemented states are:
CLOSED
OFF
POWERING_ON
POWERING_OFF
RESETTING
WAITING_INITIALIZATION
INITIALIZING
READY
WAITING_SIM
WAITING_PIN
FAILED
=vgsm_net_state Event=
Whenever the registration status of a GSM module changes, a '''vgsm_net_state''' event is generated. This event is available starting from 0.21.0.
Here follows an example of such event:
Event: vgsm_net_state
Privilege: call,all
X-vGSM-GSM-Registration: REGISTERED_HOME
Valid registration states are:
* NOT_SEARCHING
* NOT_REGISTERED
* REGISTERED_HOME
* UNKNOWN
* REGISTRATION_DENIED
* REGISTERED_ROAMING

Dovecot Sieve - How to retrieve part of message as a variable

I need to retrieve some parts of a message which looks like
Subject: Test message
Message-Id: <2788db2f-b5c3-4b8c-881e-362c3df4f915#server.local>
Mime-Version: 1.0
Content-Type: multipart/report; boundary="----=_Part_fba0c199dfcd4d60ae506b37a6320a84"; report-type=notification
To: adam#test.local
Date: Mon, 17 Sep 2018 16:21:45 -0400 (EDT)
From: postmaster#server.local
------=_Part_fba0c199dfcd4d60ae506b37a6320a84
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
BTW, this is the correct notification ... it should be "failed" not "failure".
------=_Part_fba0c199dfcd4d60ae506b37a6320a84
Content-Type: message/notification
Content-Transfer-Encoding: 7bit
Final-Recipient: rfc822; eve#test.local
Original-Message-ID: <06dbfc12-57a5-49bd-84bd-a24bc3ba1e42#fake.cernerasp>
------=_Part_fba0c199dfcd4d60ae506b37a6320a84—
for an example I need to grab what is after Final-Recipient: rfc822; and Original-Message-ID: and store them as variables
I have tried to do something like
if body :raw :contains ["Original-Message-ID:"] {
set "Original-Message-ID" "${0}";
}
but variable set as Original-Message-ID doesn't contain what is after it in the message.
It came up that the body test will definitely not work with match variables:
https://www.rfc-editor.org/rfc/rfc5173#section-6
Wildcard expressions used with "body" are exempt from the side effects
described in [VARIABLES]. That is, they MUST NOT set match variables
(${1}, ${2}...) to the input values corresponding to wildcard
sequences in the matched pattern.
The MIME Sieve extensions will likely provide what is needed
https://www.rfc-editor.org/rfc/rfc5703 or pipe message to a script and process it there, what I have done in my case.

Specify separator for JSON in Go

I want custom separators for JSON in Go, equivalent to Python's:
json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',',':'))
How to specify separator for JSON in Go ?
Clarification:
json.dumps({"key1":"value1","key2":"value2"}, separators=('__','..'))
'{"key2".."value2"__"key1".."value1"}'
There are some valid use cases for this requirement:
http://mens.com?&cyclone_data={"VisitorId":"53905341bd05ae26a9000001","CampaignId":"538f278cbd05ae36c6000001","LandingPageId":"538eac3ebd05ae15fe000001","OfferId":"538f097ebd05ae2a4d000001","SourceId":"538f0e39bd05ae2b9c000002","NetworkId":""}
I need to set this same url in cookie:
tracking_data=http://mens.com?&cyclone_data={"VisitorId":"53905341bd05ae26a9000001","CampaignId":"538f278cbd05ae36c6000001","LandingPageId":"538eac3ebd05ae15fe000001","OfferId":"538f097ebd05ae2a4d000001","SourceId":"538f0e39bd05ae2b9c000002","NetworkId":""}
After setting cookie with http.SetCookie(), Chrome Web Developer tool shows:
Date:Thu, 05 Jun 2014 11:23:46 GMT
Location:http://mens.com?&cyclone_data={"VisitorId":"53905341bd05ae26a9000001","CampaignId":"538f278cbd05ae36c6000001","LandingPageId":"538eac3ebd05ae15fe000001","OfferId":"538f097ebd05ae2a4d000001","SourceId":"538f0e39bd05ae2b9c000002","NetworkId":""}
Set-Cookie:538f278cbd05ae36c6000001=538f278cbd05ae36c6000001; Path=/
Set-Cookie:cyclone-track-url=http://mens.com?&cyclone_data={VisitorId:53905341bd05ae26a9000001CampaignId:538f278cbd05ae36c6000001LandingPageId:538eac3ebd05ae15fe000001OfferId:538f097ebd05ae2a4d000001SourceId:538f0e39bd05ae2b9c000002NetworkId:} Content-Length:378
Content-Type:text/html; charset=utf-8
, and "" are missing.
I am aware of base64. I want users to be able to change VisitorId without any manual encode/decode routine.
Server side app reads and compares this url from Cookie and Browser Referer.
Found this issue:
https://code.google.com/p/go/issues/detail?id=7243
Well, you can't directly, but if what you want is as I'm guessing to remove extra unneeded spaces, you can use json.Compact:
http://golang.org/pkg/encoding/json/#Compact
It just takes your encoded json and removes unnecessary spaces.
You can also try playing with the json.MarshalIndent method, that lets you control indentation separators. But AFAIK, you can't specify non standard separators.

Google Apps Script suddenly started throwing 'invalid mime type' errors

I have a script which processes a shared mailbox and forwards on different email (based on things like the original 'To:' header to various people. It's been working fine for months as a more flexible (and, up till now, reliable) replacement for gmail filters.
The logic is basically
Read each unprocessed message in the inbox
Look up who it was sent 'To:' (e.g. support#domain.com) which is an alias for this gmail inbox
Get a list of the intended recipients (within our organistion)
For each of those, forward the message on
Mark that message as processed, so it doesn't get re-forwarded next time
We've recently received an email which seems to trigger a weird error at the point at which the message is forwarded on. The error is:
Invalid mime type. (line 123, file "Code").
Line 123 of the script reads:
// subject: removes the 'Fwd:' prefix which we don't need, and adds the original target email in square brackets, and sets the replyTo for easy processing
really && msg.forward(rcvr, {subject: msg.getSubject() + " [" + thisTo + "]", replyTo: msg.getFrom()});
Here's a summary of the interesting bits:
really is just a boolean so we can do 'dry runs' for testing
msg is set to the current message being processed, and is of type GmailMessage
rcvr is a string with the recipient's email address
thisTo is a string holding the original 'To:' header
The message in question is a multi-part mime email with plain text and html in it. It displays just fine in gmail, and I can forward it on from there without problems. So, could anyone shed light on what the script engine is complaining about? The raw email looks like this (with some bits taken out for privacy) in case that helps pin it down:
Delivered-To: XXXX#YYYY.com
Received: by 10.182.155.73 with SMTP id vj5sqase239pbc;
Wed, 26 Jun 2013 08:50:48 -0700 (PDT)
X-Received: by 10.68.166.5 with SMTP id zc5m425et238pbb.16.1372261847795;
Wed, 26 Jun 2013 08:50:47 -0700 (PDT)
Return-Path: <support#ZZZZ.com>
Received: from mail.ZZZZ.com (mail.ZZZZ.com. [64.78.193.232])
by mx.google.com with ESMTP id vj5sqwefwe239pbc.316.2013.06.26.08.50.47
for <multiple recipients>;
Wed, 26 Jun 2013 08:50:47 -0700 (PDT)
Received-SPF: pass (google.com: domain of support#ZZZZ.com designates aa.bb.cc.dd as permitted sender) client-ip=aa.bb.cc.dd;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of support#ZZZZ.com designates aa.bb.cc.dd as permitted sender) smtp.mail=support#ZZZZ.com
Date: Wed, 26 Jun 2013 09:50:46 -0600
To: AAAA#YYYY.com, XXXX#YYYY.com
From: ZZZZ <support#ZZZZ.com>
Reply-to: ZZZZ <support#ZZZZ.com>
Subject: ZZZZ (Order #00412744)
Message-ID: <805b426783f23fec38ddafb002ce40b#admin.ZZZZ.com>
X-Priority: 3
X-Mailer: PHPMailer 5.1 (phpmailer.sourceforge.net)
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="b1_805b426783ff4601fbe72afb002ce40b"
--b1_805b426783ff4601fbe72afb002ce40b
Content-Type: text/plain; charset = "utf-8"
Content-Transfer-Encoding: 7bit
Hello Andy,
[SNIP]
and destroy all copies of the original message. Thank You
--b1_805b426783ff4601fbe72afb002ce40b
Content-Type: text/html; charset = "utf-8"
Content-Transfer-Encoding: 7bit
<html>
<head>
</head>
[SNIP]
and destroy all copies of the original message. Thank You</span></font></p></td></tr></tbody></table></body>
</html>
--b1_805b426783ff4601fbe72afb002ce40b--

Malformed JSON string, encoding issue?

I am requesting a web service and getting a JSON data as shown below. However, I keep getting the following error:
malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "\x{feff}\x{feff}{"ur...") at /usr/share/perl5/JSON/Any.pm
http request:
Date: Tue, 16 Apr 2013 10:41:03 GMT
Server: nginx/0.7.67
Content-Type: application/json; charset=utf-8
Client-Date: Tue, 16 Apr 2013 10:41:03 GMT
Client-Peer: 127.0.1.1:80
Client-Response-Num: 1
Client-Transfer-Encoding: chunked
json data:
{"url":"http:\/\/example.com\/service\/rest.htm?req_data=<auth_req><request_token>20130416f186a9c0480e2501e73d19dbcd79d354<\/request_token> <\/auth_req>&user=208860&service=auth.execute&sid=0001&format=xml&v=2.0& sign=pn9xjQjzTgQuAMarLDtiZCMaGZm4bSo8aUTGtkSt1GrxPGtK29oIL1DgHveVMwf2n7rxLHzyWrNd%2BYU6%2BxZCzs56JkMtxQMPxEJ%2Bu9Eqk5SRL6EAjWMeKheix5frPyHi0hQ4nnbiVm%2Bx3bF0KFq3cORvVCeq8wBoZU1HQXD%2BuuY%3D"}
I suspect some kind of encoding issue because the JSON string validates fine in jslint JSON validator. But I don't know what else to look for. Please help, thanks.
\x{feff} is a BOM (Byte Order Mark). I am not sure whether it is allowed at the beginning of a JSON, but it definitely should not be repeated.
thanks to choroba for prompting me to look for the BOM. Greped 3rd party library files which generates the url and surely found the BOM in them.
grep -rl $'\xEF\xBB\xBF' . # Got BOM?
perl -pi -nle 's/^\xEF\xBB\xBF//' *.lib # remove them!
cheers.