Google chrome extension Simple REST Client - rest

I am using Google chrome extension tool Simple REST Client to test my web services. How to call post method with multiple parameters. I searched in internet, there is no enough documentation for this app.
Example POST method
#POST
#Path("createcategory")
#Consumes("application/x-www-form-urlencoded")
#Produces(MediaType.APPLICATION_XML)
public void CreateCategory(#FormParam("cname") String cname,#FormParam("cdescription") String cdescription)
{
CategoriesBO category = new CategoriesBO();
category.setCategoryName(cname);
category.setCategoryDescription(cdescription);
CategoriesEntityHandler handler = new CategoriesEntityHandler();
try {
category = handler.createCategory(category);
} catch (Exception e) {
}
}

This link suggested adding
"Content-Type: application/x-www-form-urlencoded"
in the header box and a paramlist:
(param1=val1&param2=val2&...)
in the data box, which worked for me.

For "Headers", each header needs to be on a newline:
Content-Type: application/json
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36
While "Data" needs to be in json-format, so something like this:
{"login":"USERNAME","password":"PASSWORD"}
using a paramlist did not work for me.

Related

Video player on flutter web with local dart server

I have a local dart server, serving music and videos.
I tested it with android device and a flutter application and it worked with just_audio and video_player packages after adding this line in AndriodManifest.xml:
android:usesCleartextTraffic="true"
but when I am trying to run the same app on web I get an error saying:
(4) Failed to load URL
and when i tried to run another online video and audio it worked on the flutter web app
here is some snippets of my dart server code:
request.response.headers.add('Access-Control-Allow-Origin', '*');
request.response.headers.add('Access-Control-Allow-Methods', '*');
request.response.headers.add('Access-Control-Allow-Headers', '*');
and
File file = File(audioPath);
int length = await file.length();
String range = req.headers.value('range') ?? 'bytes=0-';
List<String> parts = range.split('=');
List<String> positions = parts[1].split('-');
int start = int.parse(positions[0]);
int end = positions.length < 2 || int.tryParse(positions[1]) == null
? length
: int.parse(positions[1]);
String? mime = lookupMimeType(audioPath);
response.statusCode = HttpStatus.partialContent;
response.headers
..contentType = ContentType.parse(mime ?? 'audio/mpeg')
..contentLength = end - start
..add('Accept-Ranges', 'bytes')
..add('Content-Range', 'bytes $start-$end/$length');
file.openRead(start, end).pipe(req.response);
so I think the solution to this issue is to do similar thing like this but in web:
android:usesCleartextTraffic="true"
and one more thing
when I checked for request.headers on the dart server, I didn't find the headers that I sent with the request from the frontend:
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
connection: keep-alive
accept: */*
accept-language: en-US,en;q=0.9
range: bytes=0-
accept-encoding: identity;q=1, *;q=0
host: 192.168.1.39:49359
referer: http://localhost:62278/

Why I cannot access Yobit API using webclient

The code used to work.
The URL in question is
https://yobit.net/api/3/info
It works in IE. It used to work with webclient. It doesn't work in webclient now. And I wonder what the problem is
Suddenly it stops working. So I am checking
Try
Dim wc = New WebClient
wc.Headers.Add("Accept", "text/html, application/xhtml+xml, image/jxr, */*")
wc.Headers.Add("Accept-Encoding", "gzip, deflate")
wc.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko")
wc.Headers.Add("Accept-Language", "en-US,en;q=0.5")
wc.DownloadString(URL)
Catch ex As Exception
End Try
I also tried simple version. Not working
Try
Dim wc = New WebClient
wc.DownloadString(URL)
Catch ex As Exception
End Try
In both cases yobit throw 503 access denied exception
I use fiddler and try to use internetexplorer to access directly
It works fine
GET https://yobit.net/api/3/info HTTP/1.1
Accept: text/html, application/xhtml+xml, image/jxr, */*
Accept-Language: en-US,en;q=0.5
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: yobit.net
Connection: Keep-Alive
Cookie: __cfduid=de63c60d603f271520b9ee58dfdd257061517932785; cf_clearance=7e58588df28b267842f753567dcdc475d29679a6-1517932789-86400; locale=en
If I use webclient this is the header
GET https://yobit.net/api/3/info HTTP/1.1
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.5
Accept: text/html, application/xhtml+xml, image/jxr, */*
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Host: yobit.net
Connection: Keep-Alive
Almost the exact same thing.
Let me try another URL
Say http://google.com
GET http://www.google.com/ HTTP/1.1
Accept: text/html, application/xhtml+xml, image/jxr, */*
Accept-Language: en-US,en;q=0.5
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: www.google.com
Connection: Keep-Alive
Cookie: NID=121=GUd4VKHT_gcwUx-hK39mphuCg93Q_W2fL_yCc-JO3AJkgh74EGajif0537eraLK8ns2EdEQPexOOeBxSlOxVrj8t_AVn21FRme2hAxuLXz4F8aCZExIzME4jaYMBuUp_lnak5Q; OGPC=19004116-3:; 1P_JAR=2018-1-9-7
If I use webclient
GET http://google.com/ HTTP/1.1
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.5
Accept: text/html, application/xhtml+xml, image/jxr, */*
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Host: google.com
Connection: Keep-Alive
Both works.
There could be different issues here
Framework Version
You recently changed the framework version and that has some issue which causes it not to work. You can change the framework versions and see if it helps
Compression of Data
WebClient by default is not doing decompression and you add headers to request gzip data if available. Now there is a possibility that the site didn't enable gzip earlier which made it work for you and now they have enabled gzip responses. You can fix that by changing
wc.Headers.Add("Accept-Encoding", "gzip, deflate")
to
wc.Headers.Add("Accept-Encoding", "deflate")
Or if you want the data to come in compressed form only, then you can enable auto decompression as shown in below code
class Program
{
class MyWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
{
var request = base.GetWebRequest(address) as HttpWebRequest;
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
return request;
}
}
public static void Main(string[] args)
{
var URL = "https://yobit.net/api/3/info";
var wc = new WebClient();
wc.Headers.Add("Accept", "text/html, application/xhtml+xml, image/jxr, */*");
wc.Headers.Add("Accept-Encoding", "gzip, deflate");
wc.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko");
wc.Headers.Add("Accept-Language", "en-US,en;q=0.5");
Console.WriteLine(wc.DownloadString(URL));
// TODO: Implement Functionality Here
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
The above example is C# and not VB.NET but you can easily convert it

Personal Access token in Gist

I've created a personal access token (https://github.com/settings/tokens) giving Gist perms.
I'm trying to use it to create a gist but I'm getting
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3"
}
My request is:
POST /gist HTTP/1.1
Host: api.github.com
Connection: close
X-Client-Data: CJO2yQEIorbJAQjBtskBCPqcygEIqZ3KAQjSncoBCKijygE=
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
Accept-Language: en-US,en;q=0.8,es;q=0.6
Authorization: Basic blablablablablabla
Content-Length: 142
{
"description": "the description for this gist",
"files": {
"file1.txt": {
"content": "String file contents"
}
}
}
Can't personal tokens being used to post in gist?
The problem is that Basic authentication should not be used but a specific header to provide the token. The request should be:
POST /gist HTTP/1.1
Host: api.github.com
Connection: close
X-Client-Data: CJO2yQEIorbJAQjBtskBCPqcygEIqZ3KAQjSncoBCKijygE=
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
Accept-Language: en-US,en;q=0.8,es;q=0.6
Authorization: token aabbaabbaabbabababababababababababababab
Content-Length: 142
{
"description": "the description for this gist",
"files": {
"file1.txt": {
"content": "String file contents"
}
}
}

scala play framework 2.2.6 encoding issue

I got a form in my application. I input there russian and chineese symbols. Http request from browser to application looks like this:
POST /payout/process HTTP/1.0
Host: my_host
X-Real-IP: 10.3.4.6
X-Forwarded-For: 10.3.4.6
X-Forwarded-Proto: https
Connection: close
Content-Length: 286
Accept: */*
Origin: https://my_host
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/43.0.2357.130 Chrome/43.0.2357.130 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: https://my_host
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,ru;q=0.6
Cookie: piwikExternalId=; COOKIEPOO="d14ef459332e84ab12f8187181e01e50df3abd61-5d635c8478334352d2865b11dd747d6d3fe84704=1&d6e2c1ad27a45b7d9b8ed7b039ab96c7d3ef8051=1&7cf1199693fa6d40bf3654db17ec4773e0d61f38=1"
group=27&qwipi.customer_name=%D1%84%D1%8B%D0%B2&qwipi.bank_code=%E6%8B%9B%E5%95%86%E9%93%B6%E8%A1%8C&qwipi.bank_branch=%D1%84%D0%B2%D0%B0&customer_purse=%D1%84%D1%8B%D0%B2%D0%B0&qwipi.bank_city=%D1%84%D0%B2%D1%8B%D0%B0&qwipi.bank_province=%E6%8B%9B%E5%95%86%E9%93%B6%E8%A1%8C&amount=546
Check out request body, parameter customer_name. Decoded it will give фыв. Chec out paramter bank_branch. Decoded it will give 招商银行.
I log the request to console and graylog like this:
def logRequest(request: Request[AnyContent]) {
request.body match {
case AnyContentAsFormUrlEncoded(data) => Logger.info(data.toString())
case AnyContentAsText(text) => Logger.info(text + ", ")
case other => Logger.info(other.toString())
}
}
and I get something like
body: 'qwipi.bank_code' => '??????', 'qwipi.bank_province' => '??????', 'qwipi.customer_name' => '??????', 'amount' => '654', 'qwipi.bank_branch' => '??????', 'qwipi.bank_city' => '??????'
i.e., all non-latin symbols turn to question signs.
echo $LANG outputs en_US.UTF-8, so I guess my application's encoding (whatever that means -- application's itself or java's or playframework's or smth else) is different.
This is what I tried:
def logRequest(request: Request[AnyContent]) {
Logger.info(new String(appendRequestData(request).getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8))
}
i.e., got the byte array in UTF-8 and turn it into the String which is in UTF-8 as well. But nothing changed.
What I also tried was starting an application passing -Dfile.encoding=UTF8 key -- the result still the same.
So how can I make my stuff logged properly? What things I might have missed?
It didn't help converting my string from one encoding to another on the fly. It didn't help passing UTF-8 to scalac option in Build.scala like that
So I just passed -Dfile.encoding=UTF-8 when starting my java service.

angularjs restangular customPUT with Slim php restful framework

I am trying to update database using SLIM php. But the form data values passed in are showing blank. I have been successful in posting (customPOST) the values.
Here is the code:
AngularJs:
UpdateCategoryFormData:function(category,catId){
formData=new FormData();
angular.forEach(category, function (fieldData, field) {
formData.append(field, fieldData);
});
return Restangular.one('category/update',catId)
.withHttpConfig({transformRequest: angular.identity})
.customPUT(formData, undefined, {}, {'Content-Type': undefined});
}
SLIM php:
$app->put('/category/update/:catId',function($catId) use($app){
$data=$app->request->put();
print_r($data);
$catName=$app->request->put('catName');
$catParent=$app->request->put('catParent');
Result is:
array()
echo $catName;
I am getting a blank as the value of $catName;
Here is the copy of the headers:
Request Method:PUT
Status Code:200 OK
Response Headers
view source
Connection:Keep-Alive
Content-Length:10
Content-Type:text/html
Date:Fri, 28 Aug 2015 03:48:28 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.4.9 (Win32) PHP/5.5.12
X-Powered-By:PHP/5.5.12
Request Headers
view source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:249
Content-Type:multipart/form-data; boundary=----WebKitFormBoundary4gUX2gCt7zCICZNN
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2489.0 Safari/537.36
Request Payload
------WebKitFormBoundary4gUX2gCt7zCICZNN
Content-Disposition: form-data; name="catName"
Some Category
------WebKitFormBoundary4gUX2gCt7zCICZNN
Content-Disposition: form-data; name="catParent"
45
------WebKitFormBoundary4gUX2gCt7zCICZNN--
Can someone help pls!