Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
117 views
in Technique[技术] by (71.8m points)

php - Send POST data with URL

I'm using SKETCHWARE for framework make send BUTTON, but that's not the problem.

The problem is, how to send DATA with POST METHOD? HERE my HTML also PHP in one file.

<html>
  <form action="index.php" method="POST">
    <input type="hidden" name="data">
  </form>
</html>
<?php
if (isset($_POST["data"]))
{
  $data=$_POST["data"];
  appendData("./database.txt",$data);//CONSIDER THIS FUNCTION IS APPENDING DATA with first parameter is file location and second parameter is content.
}
else {
  echo("NoT SET");
}
?>

And this is the syntax (block code) in sketchware. Im just using first syntax because i dont know the that second and third function maybe you guys understand how it work and maybe can solve my problem. enter image description here

before i use POST method, i was using with GET method with data input in URL, due to GET method limited to 1024character so i decide to use POST method with url, the problem is, it didnt send data like GET method.

question from:https://stackoverflow.com/questions/66065052/send-post-data-with-url

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

GET is a type of a HTTP request where the parameter are stored in the url itself, whilst POST requests stores the data inside the request parameter, and it's format can be changed by using the Content-Type HTTP header.

To put a data in the body, Create a Map. In that map, you can put whatever data you're sending, this case, is "data"="SENDED"

Use [[Map: ] put key ["data"] value ["SENDED"]] to add the data to the map

Use the [[RequestNetwork: ] set params [Map: ] to request type [REQUEST_PARAM]] block to place that map you created as the request body for the post request

Final Code:

variables:
 - payload -> Map

Components:
 - rn -> RequestNetwork

Code:
[Map: put key ["data"] value ["SENDED"]]
[[RequestNetwork: rn] set params [Map: payload] to request type [REQUEST_PARAM]]
[[RequestNetwork: codes] start network request to method [GET] to url ["https://example.com"] with tag []]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...