Kotlinx-serialization-json: java.util.NoSuchElementException: List is empty - kotlin

I get error "java.util.NoSuchElementException: List is empty." from Kotlinx-serialization-json cause the body`s contentLenght is -1. But it is 44 bytes if check in interceptor. I guess this property (contentLenght in RealResponseBody) should be forced to 44 in interceptor. Or force Kotlinx-serialization-json to ignore this property when serializing.
I use Retrofit, RxJava and Serialization:
// RxJava
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
implementation "io.reactivex.rxjava2:rxjava:2.2.21"
implementation "io.reactivex.rxjava2:rxkotlin:2.4.0"
implementation "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0"
implementation "com.jakewharton.rxrelay2:rxrelay:2.1.1"
// Retrofit
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.okhttp3:logging-interceptor:4.9.1"
implementation "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0"
// Serialization
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2"
My interceptor:
override fun intercept(chain: Interceptor.Chain): Response {
val originalResponse = chain.proceed(chain.request())
val builder = originalResponse.newBuilder()
.addHeader("Content-Length", (originalResponse.body?.bytes()?.size ?: 0).toString())
.build()
return builder
}
My Response:
2022-03-20 11:54:04.936 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: --> POST https://test.hide/api/v4/registration/sign_in/
2022-03-20 11:54:04.936 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: Content-Type: application/json; charset=utf-8
2022-03-20 11:54:04.936 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: Content-Length: 281
2022-03-20 11:54:04.937 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: {"number":"123123123","last_name":"Test","email":"index#gmail.com","fcm_token":"fxktgapBQVe3pOior0dUJ-:APA91bGPpa_uFfurGg7mKurOHHdEB7ipZHG_KkBrE2V5F476ErB7FcEQorG5-X6BTXC3jrtmVKItYvVxrTyWMILXxdw-1w8kYNRgDtL54f5uBNda_4gYV5Ij8oaC1prHyu9x_uSZ4zsw","device_os":"Android"}
2022-03-20 11:54:04.937 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: --> END POST (281-byte body)
2022-03-20 11:54:04.940 6536-6604/com.example.app2_kotlin D/test: Here is cookie https://test.hide/api/v4/registration/sign_in/
2022-03-20 11:54:05.435 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: <-- 200 OK https://test.hide/api/v4/registration/sign_in/ (498ms)
2022-03-20 11:54:05.435 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: Server: nginx/1.11.13
2022-03-20 11:54:05.435 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: Date: Sun, 20 Mar 2022 08:54:06 GMT
2022-03-20 11:54:05.435 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: Content-Type: application/json
2022-03-20 11:54:05.435 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: Transfer-Encoding: chunked
2022-03-20 11:54:05.436 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: Connection: keep-alive
2022-03-20 11:54:05.436 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: Allow: POST, OPTIONS
2022-03-20 11:54:05.436 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: Vary: Origin
2022-03-20 11:54:05.437 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: {"message": "User successfully registered."}
2022-03-20 11:54:05.437 6536-6604/com.example.app2_kotlin I/okhttp.OkHttpClient: <-- END HTTP (44-byte body)

The problem was in "Tranfer-Encoding" header. It was "gzip". Using this header tell the server that client is receiving packed data in response. The server in this case begins to return data in a "split" form.
So the solution is not to use this header.

Related

New to VBA : MSXML2.XMLhttp strips session cookies from POST response

I am very new to VBA and trying to scrape through a website. So far I have been able to get cookies from initial get request and use them in POST for a successful login. The next step is to capture the session and user cookies and use them in the subsequent requests.
Unfortunately, this is where my problem begins.
Post successful login I am using .getAllResponseHeaders() to capture all headers but it seems the two cookies (Set-Cookie: xf_user AND Set-Cookie: xf_session) are missing and hence I am not able to capture them for later use. For comparison and easier understanding, I am posting the fiddler (correct) response and response captured by vba (incorrect).
I am not sure what am I doing wrong. Please suggest any options, I am happy to take an alternate approach. I am sure I am very close to success, just need your expert advice.
Fiddler Response
HTTP/1.1 303 See Other
Date: Thu, 30 Apr 2020 04:55:14 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Last-Modified: Thu, 30 Apr 2020 04:55:24 GMT
Location: https://f95zone.to/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: private, no-cache, max-age=0
Set-Cookie: xf_user=19872%2CUsOoxkBS4bzvLttbYhWkicE-JFQ-vBWo2L68LEVS; expires=Fri, 30-Apr-2021 04:55:24 GMT; Max-Age=31536000; path=/; secure; HttpOnly
Set-Cookie: xf_session=nlJRIrZOrbAiQGVAo_wRJhDSKBsy7wKz; path=/; secure; HttpOnly
Strict-Transport-Security: max-age=15768000
CF-Cache-Status: DYNAMIC
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 58beab553a76fea5-MEL
alt-svc: h3-27=":443"; ma=86400, h3-25=":443"; ma=86400, h3-24=":443"; ma=86400, h3-23=":443"; ma=86400
cf-request-id: 026b0969420000fea583bd8200000001
Content-Length: 0
VBA Response
date: Thu, 30 Apr 2020 13:47:02 GMT
content-type: text/html; charset=utf-8
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
last-modified: Thu, 30 Apr 2020 13:47:01 GMT
expires: Thu, 19 Nov 1981 08:52:00 GMT
cache-control: private, no-cache, max-age=0
strict-transport-security: max-age=15768000
cf-cache-status: DYNAMIC
expect-ct: max-age=604800, report-uri=""https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct""
server: cloudflare
cf-ray: 58c1b6504d3dfe8d-MEL
alt-svc: h3-27="":443""; ma=86400, h3-25="":443""; ma=86400, h3-24="":443""; ma=86400, h3-23="":443""; ma=86400
cf-request-id: 026cf0462f0000fe8d47804200000001
Snippet From My Code
Set objXMLHTTPSearch = CreateObject("MSXML2.XMLHTTP")
objXMLHTTPSearch.Open "POST", "https://f95zone.to/login/login", False
objXMLHTTPSearch.setRequestHeader "Accept", "text/html, application/xhtml+xml, image/jxr, */*"
objXMLHTTPSearch.setRequestHeader "Accept -Language", "en -US"
objXMLHTTPSearch.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
objXMLHTTPSearch.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objXMLHTTPSearch.setRequestHeader "Accept -Encoding", "gzip , deflate"
objXMLHTTPSearch.setRequestHeader "Host", "f95zone.to"
objXMLHTTPSearch.setRequestHeader "Content-Length", Len(dataSTR)
objXMLHTTPSearch.setRequestHeader "Connection", "Keep -Alive"
objXMLHTTPSearch.setRequestHeader "cache -Control", "no-cache"
objXMLHTTPSearch.withCredentials = True
objXMLHTTPSearch.send dataSTR
statusSearch = objXMLHTTPSearch.status
fetchHeader = objXMLHTTPSearch.getAllResponseHeaders()

Jsessionid Jmeter after login to site

what should i do to corelate i can use different login in jmeter i have already parameterize the value. i am getting stuck with this jsession id
Sample Count: 1
Error Count: 0
Data type ("text"|"bin"|""): text
Response code: 200
Response message: OK
Response headers:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-AREQUESTID: 340x9129744x1
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
X-ASEN: SEN-1047238
Set-Cookie: atlassian.xsrf.token=AVWR-AYBS-V3UU-QQRS|fef17187ee7e13e93c498a08e44fb5c2b90aba75|lout; Path=/
X-AUSERNAME: anonymous
X-Content-Type-Options: nosniff
Set-Cookie: JSESSIONID=3075A3A258CBA5D6131F724E3C0800CC; Path=/; HttpOnly
X-Accel-Buffering: no
Vary: User-Agent
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Sun, 07 Oct 2018 09:40:27 GMT
Content-Encoding: gzip
HTTPSampleResult fields:
ContentType: text/html;charset=UTF-8
DataEncoding: UTF-8

QuickBlox delete dialog returns access denied

I wrote a helper using Jersey to delete a dialog on QuickBlox. For some reason, the same delete request generated by curl returns without any errors but with Jersey (a java restful client library) returns a 403. Here are the packet traces (taken on wireshark) of the requests and responses:
Jersey Request:
DELETE /chat/Dialog/55c5fab8535c12a211000d0f.json HTTP/1.1\r\n
Accept: */*\r\n
QB-Token: 32a7acd55d3b21dad79afba3b834a0b62c9a4946\r\n
User-Agent: Jersey/2.19 (HttpUrlConnection 1.8.0_20)\r\n
Host: api.quickblox.com\r\n
Connection: keep-alive\r\n
\r\n
Jersey Response:
Hypertext Transfer Protocol
HTTP/1.1 403 Access Denied\r\n
Date: Sat, 08 Aug 2015 12:49:14 GMT\r\n
Connection: keep-alive\r\n
Cache-Control: no-store\r\n
Content-Type: text/html\r\n
Content-Language: en\r\n
Content-Length: 249\r\n
\r\n
[HTTP response 2/2]
[Time since request: 0.009155000 seconds]
[Prev request in frame: 24303]
[Prev response in frame: 24324]
[Request in frame: 24328]
Line-based text data: text/html
<HTML>\n
<HEAD>\n
<TITLE>Access Denied</TITLE>\n
</HEAD>\n
\n
<BODY BGCOLOR="white" FGCOLOR="black">\n
<H1>Access Denied</H1>\n
<HR>\n
\n
<FONT FACE="Helvetica,Arial"><B>\n
Description: You are not allowed to access the document you requested.\n
</B></FONT>\n
<HR>\n
</BODY>\n
Curl Request:
Hypertext Transfer Protocol
DELETE /chat/Dialog/55c5fab8535c12a211000d0f.json HTTP/1.1\r\n
User-Agent: curl/7.37.1\r\n
Host: api.quickblox.com\r\n
Accept: */*\r\n
QB-Token: 32a7acd55d3b21dad79afba3b834a0b62c9a4946\r\n
\r\n
[Full request URI: http://api.quickblox.com/chat/Dialog/55c5fab8535c12a211000d0f.json]
[HTTP request 1/1]
[Response in frame: 35345]
Curl Response:
Hypertext Transfer Protocol
HTTP/1.1 200 OK\r\n
Access-Control-Allow-Origin: *\r\n
Cache-Control: max-age=0, private, must-revalidate\r\n
Content-Type: application/json; charset=utf-8\r\n
Date: Sat, 08 Aug 2015 12:54:34 GMT\r\n
ETag: "7215ee9c7d9dc229d2921a40e899ec5f"\r\n
QB-Token-ExpirationDate: 2015-08-08 14:49:14 UTC\r\n
QuickBlox-REST-API-Version: 0.1.1\r\n
Server: nginx/1.0.15\r\n
Status: 200 OK\r\n
X-Rack-Cache: invalidate, pass\r\n
X-Request-Id: 129dfcd4199bcae1f61cbd55a435885d\r\n
X-Runtime: 0.036879\r\n
X-UA-Compatible: IE=Edge,chrome=1\r\n
Content-Length: 1\r\n
Connection: keep-alive\r\n
\r\n
[HTTP response 1/1]
[Time since request: 0.475311000 seconds]
[Request in frame: 35287]
JavaScript Object Notation: application/json
Line-based text data: application/json
Does anyone have any idea what's happening here?

Add Headers to a POST

I am trying to pass header when i post XML Data in VB.Net.
It needs to look like this :
POST /test1.asmx HTTP/1.1
Host: www.test1.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://test1.org/PostApplication_V5"
I am using the following :
Req.Headers.Add("POST /", "test1.asmx HTTP/1.1")
Req.Headers.Add("HOST", "www.test1.com")
Req.Headers.Add("Content-Type", "text/xml; charset=utf-8")
Req.Headers.Add("Content-Length", "length")
Req.Headers.Add("SOAPAction", """http://test1.org/PostApplication_V5""")
Its not working
<POST /test1.asmx HTTP/1.1>
<Host: www.test1.com>
<Content-Type: text/xml; charset=utf-8>
<Content-Length: length>
<SOAPAction: "http://test1.org/PostApplication_V5">
</POST /test1.asmx HTTP/1.1>
</Host: www.test1.com>
</Content-Type: text/xml; charset=utf-8>
</Content-Length: length>
</SOAPAction: "http://test1.org/PostApplication_V5">

So nginx is not interpreting folded headers correctly?

HTTP/1.1 header field values can be
folded onto multiple lines if the
continuation line begins with a space
or horizontal tab. All linear white
space, including folding, has the same
semantics as SP. A recipient MAY
replace any linear white space with a
single SP before interpreting the
field value or forwarding the message
downstream.(quoted from here)
Here's my server side script,which just dumps the cookie content:
var_dump($_COOKIE);exit;
Here comes my test,please pay attention to the cookie part:
GET /logtest.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.17) Gecko/20110420 AlexaToolbar/alxf-2.11 Firefox/3.6.17
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Cookie: A=t;
artDate=t
Cache-Control: max-age=0
HTTP/1.1 200 OK
Server: iis/8.0
Date: Mon, 23 May 2011 12:38:00 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/5.3.2
Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/
27
array(1) {
["A"]=>
string(1) "t"
}
0
GET /logtest.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.17) Gecko/20110420 AlexaToolbar/alxf-2.11 Firefox/3.6.17
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Cookie: A=t;
artDate=t
Cache-Control: max-age=0
HTTP/1.1 200 OK
Server: iis/8.0
Date: Mon, 23 May 2011 12:38:11 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/5.3.2
Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/
27
array(1) {
["A"]=>
string(1) "t"
}
0
GET /logtest.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.17) Gecko/20110420 AlexaToolbar/alxf-2.11 Firefox/3.6.17
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Cookie: A=t;artDate=t
Cache-Control: max-age=0
HTTP/1.1 200 OK
Server: iis/8.0
Date: Mon, 23 May 2011 12:38:55 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/5.3.2
Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/
47
array(2) {
["A"]=>
string(1) "t"
["artDate"]=>
string(1) "t"
}
0
It's a known issue that doesn't have a high priority.