我想使用谷歌API来创建Gmail用户帐户.我正在向服务器发送JSON请求以获取授权代码,但我在httpwebresponse中收到了这些错误: -
异常详细信息:System.Net.WebException:远程服务器返回错误:(400)错误请求
var request = (HttpWebRequest)WebRequest.Create(@"https://accounts.google.com/o/oauth2/auth");
request.Method = "POST";
request.ContentType = "text/json";
request.KeepAlive = false;
//request.ContentLength = 0;
using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream()))
{
string json = "{\"scope\":\"https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile\"," + "\"state\":\"%2Fprofile\"," + "\"redirect_uri\":\"http://gmailcheck.com/response.aspx\"," + "\"response_type\":\"code\"," + "\"client_id\":\"841994137170.apps.googleusercontent.com\"}";
streamWriter.Write(json);
// streamWriter.Flush();
//streamWriter.Close();
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
StreamReader responsereader = new StreamReader(response.GetResponseStream());
var responsedata = responsereader.ReadToEnd();
//Session["responseinfo"] = responsereader;
//testdiv.InnerHtml = responsedata;
}
}
Run Code Online (Sandbox Code Playgroud) 我是php的新手.我有一个jQuery脚本,将生成新元素.用户单击"提交"并转到page2.php.这就是我需要一个php循环来确定用户创建了多少文本输入的地方.
page1.php中
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.min.js'> </script>
<script type='text/javascript'>
$(document).ready(function() {
$('#btn').click(function() {
var x = parseInt($('#hidtxt').val()) + (1*1);
var z = "<input type='text' id='txt" + x + "' name='txt" + x + "' size='10'/>";
$('#main').append(z);
$('#hidtxt').val(x);
});
});
</script>
</head>
<body>
<form name='myform' action='page2.php' method='post'/>
<input type='hidden' value='1' name='hidtxt' id='hidtxt'/>
<div id='main'>
<input type='text' id='txt1' name='txt1' size='10'/>
</div>
<input type='button' id='btn' name='btn' value='Add Text Box'/>
<input type='submit' value='Submit' id='subBtn' name='subBtn'/>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
然后是page2.php
<?php
//CREATE …Run Code Online (Sandbox Code Playgroud) 我找到了这个主题(如何从jQuery.ajax获取响应状态代码?),其中它解释了如何获得返回状态,但我正在使用$.post它使它有点不同.
我有以下代码:
$(function() {
$('#update_marker').submit( function(e) {
e.preventDefault();
$.post($("#update_marker").attr("action"), $("#update_marker").serialize(), function(data) {
if( $.trim(data).indexOf('<')==0 ) {
new Messi( lang['dist_general_error'], {title: 'Ops...', titleClass: 'anim error', buttons: [{id: 0, label: 'Fechar', val: 'X'}]});
} else {
var json = $.parseJSON( data );
if( json.status=="success" ) {
new Messi( json.msg );
} else {
new Messi( json.msg, {title: 'Ops..', titleClass: 'anim error', buttons: [{id: 0, label: 'Fechar', val: 'X'}]});
}
}
});
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
所以我以为我会把$.post呼叫改成类似的东西 …
如何在使用刀片模板系统的Laravel框架中的任何视图页面上打印回发数据.
$ _POST ['state']没有给出任何结果.
我正在使用以下代码将图像发布到服务器.
var image= Image.FromFile(@"C:\Image.jpg");
Task<string> upload = Upload(image);
upload.Wait();
public static async Task<string> Upload(Image image)
{
var uriBuilder = new UriBuilder
{
Host = "somewhere.net",
Path = "/path/",
Port = 443,
Scheme = "https",
Query = "process=false"
};
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("locale", "en_US");
client.DefaultRequestHeaders.Add("country", "US");
var content = ConvertToHttpContent(image);
content.Headers.ContentType = MediaTypeHeaderValue.Parse("image/jpeg");
using (var mpcontent = new MultipartFormDataContent("--myFakeDividerText--")
{
{content, "fakeImage", "myFakeImageName.jpg"}
}
)
{
using (
var message = await client.PostAsync(uriBuilder.Uri, mpcontent))
{
var input …Run Code Online (Sandbox Code Playgroud) 虽然我还在阅读Nicholas C. Zakas的书(在4天内阅读了300多页),但同时我还有一个小项目,为我们后来的大项目创建一个半自动化的文档生成器页面.这已经完成了一半,但现在我想给它提供更多的功能,这需要我将textareas的值发送给PHP,因此PHP可以更新mysql而反之亦然,但现在不是问题.
问题: Ajax成功,我得到了成功消息,但PHP没有读取POST.为什么?
我做了我的研究,我阅读了stackoverflow主题和其他网站,phpmanual,w3school示例的音调,但出了点问题.
<form id="foo">
<label for="bar">A bar</label>
<input id="bar" name="bar" type="text" value="" />
<input type="submit" value="Send" />
</form>
<div id="result"></div>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="script.js"></script>
Run Code Online (Sandbox Code Playgroud)
/* Attach a submit handler to the form */
$("#foo").submit(function(event) {
/* Stop form from submitting normally */
event.preventDefault();
/* Clear result div*/
$("#result").html('');
/* Get some values from elements on the page: */
var values = $("#foo").serialize();
console.log("val: "+values);
/* Send the data using post and put the results …Run Code Online (Sandbox Code Playgroud) 在PHP页面上,我的页面上有隐藏字段的按钮:
<form action="admin.php">
<input name="action" value="delete" type="hidden">
<input name="id" value="13" type="hidden">
<input value="Delete user" type="submit">
</form>
Run Code Online (Sandbox Code Playgroud)
在页面admin.php我有这个:
switch ($_POST['action'])
{
case 'delete' :
if ($_SESSION['role'] == 2)
{
if ($user->deleteUser($_POST['id']))
{
$_SESSION['alert'] = "User deleted.";
$_SESSION['alert_type'] = "success";
} else
{
$_SESSION['alert'] = "Something went wrong while deleting the user.";
$_SESSION['alert_type'] = "error";
}
} else
{
$_SESSION['alert'] = "You are not allowed to delete a user. You need to be an admin.";
$_SESSION['alert_type'] = "error";
}
$data = $user->getProfiles(); …Run Code Online (Sandbox Code Playgroud) 我开始使用Play 2.2.x,我正在尝试处理POST请求,我的理解是我不需要在conf/routes文件中指定参数,而是使用play的DynamicForm类提取查询,如下所示:
import play.*;
import play.api.data.Form;
import play.data.DynamicForm;
import play.mvc.*;
import views.html.*;
public static Result hello() {
DynamicForm requestData = Form.form().bindFromRequest();
String firstname = requestData.get("firstname");
String lastname = requestData.get("lastname");
return ok("Hello " + firstname + " " + lastname);
}
Run Code Online (Sandbox Code Playgroud)
但是,我在Eclipse中遇到此错误:
"The method form() is undefined for the type Form
Run Code Online (Sandbox Code Playgroud)
当我执行"play run"时,我得到了这个编译器:
error: cannot find symbol
DynamicForm data = Form.form().bindFromRequest();
Run Code Online (Sandbox Code Playgroud)
这段代码有什么问题?这个类或方法是否已弃用?
谢谢!
我有这样的形式:
<form action="addScript.php" methot="POST" enctype="multipart/form-data">
<tr>
<td>Produt title : </td><td><input type="text" name="title" id="title" /></td>
</tr>
<tr>
<td>Product description : </td><td><textarea rows="5" cols="40" name="description" id="description"></textarea></td>
</tr>
<tr>
<td>Price (USD $) : </td><td><input type="text" name="price" id="price" /></td>
</tr>
<tr>
<td>Profile Picture : </td><td><input type="file" name="profilepic" id="profilepic" /></td>
</tr>
<tr>
<td>Other pictures : </td><td>
<div id="pictures" style="border:1px solid black;"><table>
<tr><td>1</td><td><input type="file" id="pic1" name="pic1" /></td></tr>
<tr><td>2</td><td><input type="file" id="pic2" name="pic2" /></td></tr>
<tr><td>3</td><td><input type="file" id="pic3" name="pic3" /></td></tr>
</table>
</div>
</td>
</tr>
<tr>
<td></td><td><input type="submit" value="Add" /></td> …Run Code Online (Sandbox Code Playgroud) //include.php
define('OPTION_0', 'Essence of population');
define('OPTION_1', 'Passport request/extend');
define('OPTION_2', 'Request logging concession');
//form.php
<select name="sort">
<option value="0"><?php echo(O_0) ?></option>
<option value="1"><?php echo(O_1) ?></option>
<option value="2"><?php echo(O_2 ?></option>
</select>
//show.php
extract($_POST); //The variable $sort has the value 1,2 or 3
echo("This is your choice");
echo(OPTION_ . $sort); //I want to use de constant e.g. OPTION_2
Run Code Online (Sandbox Code Playgroud)
我想回应匹配常量的值.所以当我在form.php中选择第二个值时,它给$ sort值1现在我想使用常量OPTION_1.
有人能帮我吗?