Escaping Parameters in Set_Form_Data Post

Escaping parameters in set_form_data POST

It's not OK that this happens: PHP, Java, Node -- none of them do this.

First, I override:

# Module to override
module Net
module HTTPHeader
def postUrlBuilder(postParams)
@queryUrl = ''
if (postParams.nil? or postParams == 0)
# Null or empty item
else
count = 0
postParams.each_pair do |key,value|
if (count == 0)
@queryUrl = @queryUrl + key + '=' + value
count = count + 1
else
@queryUrl = @queryUrl + '&' + key + '=' + value
end
end
end
return @queryUrl
end

def set_form_data(postParams, sep = '&')
self.body = postUrlBuilder(postParams)
self.content_type = 'application/x-www-form-urlencoded'
end
alias form_data= set_form_data
end
end

Then I wrote my own post method:

def monkey_patch_post_request(postParams)
url = URI.parse(@monkeyPatchUrl)
req = Net::HTTP::Post.new(url.path)
req.basic_auth @companyId, @apiKey
req.set_form_data(postParams, sep = '&')
sock = Net::HTTP.new(url.host, 443)
sock.use_ssl = true
sock.ssl_version='SSLv3'
sock.start do |http|
response = http.request(req)
return response.body
end
end

This should help!

JSOUP: set form data

you could just search what you want by manipulating the url's endpoint:

http://wordnetweb.princeton.edu/perl/webwn?s= and concatenating what you want to search to it.

if the word you're searching for was "bill" then

/*
* returns url of search term using jsoup
*/
public static String getUrl(String search) throws IOException{
String url = "http://wordnetweb.princeton.edu/perl/webwn?s=";
Document doc = Jsoup.connect(url + search).get();
String newURL = doc.location().toString();
System.out.println(newURL);
return (newURL);
}

then if you just wanted to test if a word was a word you could do this

/*
* returns true if is a word
*/
public static boolean isWord(String search) throws IOException{

String url = "http://wordnetweb.princeton.edu/perl/webwn?s=";
String notAWord = "Your search did not return any results.";

Document doc = Jsoup.connect(url + search).get();
String searchH3 = doc.select("h3").text();

return searchH3.contains(notAWord) ? false : true;

}

if you want to make the post request however you could do it by using Connection.Response to get the response of your post. You just need to have import org.jsoup.Connection as an import to use the Connection API.

public static String getUrl(String search) throws IOException{

Connection.Response wordForm = Jsoup.connect("http://wordnetweb.princeton.edu/perl/webwn")
.method(Connection.Method.GET)
.execute();

String url = "http://wordnetweb.princeton.edu/perl/webwn";
Document doc = Jsoup.connect(url)
.data("s", search)
.data("o2", "")
.data("o0", "1")
.data("o8", "1")
.data("o1", "1")
.data("o7", "")
.data("o5", "")
.data("o9", "")
.data("o6", "")
.data("o3", "")
.data("o4", "")
.data("h", "")
.cookies(wordForm.cookies())
.post();

System.out.println(doc);

String newURL = doc.location().toString();
return (newURL);
}

A similar example can be found here

How to send form data in POST request in Swift 3

my calling api class

class ApiService
{
static func getPostString(params:[String:Any]) -> String
{
var data = [String]()
for(key, value) in params
{
data.append(key + "=\(value)")
}
return data.map { String($0) }.joined(separator: "&")
}

static func callPost(url:URL, params:[String:Any], finish: @escaping ((message:String, data:Data?)) -> Void)
{
var request = URLRequest(url: url)
request.httpMethod = "POST"

let postString = self.getPostString(params: params)
request.httpBody = postString.data(using: .utf8)

var result:(message:String, data:Data?) = (message: "Fail", data: nil)
let task = URLSession.shared.dataTask(with: request) { data, response, error in

if(error != nil)
{
result.message = "Fail Error not null : \(error.debugDescription)"
}
else
{
result.message = "Success"
result.data = data
}

finish(result)
}
task.resume()
}
}

and when use it

ApiService.callPost(url: url, params: params, finish: finishPost)

and the finish function

func finishPost (message:String, data:Data?) -> Void
{
do
{
if let jsonData = data
{
let parsedData = try JSONDecoder().decode(Response.self, from: jsonData)
print(parsedData)
}
}
catch
{
print("Parse Error: \(error)")
}
}

Can I append an array to 'formdata' in javascript?

How about this?

formdata.append('tags', JSON.stringify(tags));

... and, correspondingly, using json_decode on server to deparse it. See, the second value of FormData.append can be...

a Blob, File, or a string, if neither, the value is converted to a
string

The way I see it, your tags array contains objects (@Musa is right, btw; making this_tag an Array, then assigning string properties to it makes no sense; use plain object instead), so native conversion (with toString()) won't be enough. JSON'ing should get the info through, though.

As a sidenote, I'd rewrite the property assigning block just into this:

tags.push({article: article, gender: gender, brand: brand});

GraphQL + React: Could not find client in the context or passed in as an option

remove:

"@apollo/react-hooks": "^4.0.0",

when using client you dont need to use hooks.

This one for your other question:

import { useMutation } from '@apollo/client';


Related Topics



Leave a reply



Submit