Tag: 职位

Rails表单中的多个对象

我想以一种forms编辑我的模型照片的多个项目。 我不确定如何正确地呈现和POST这个表单,以及如何收集在控制器更新行动中的项目。 这就是我要的: <form> <input name="photos[1][title]" value="Photo with id 1" /> <input name="photos[2][title]" value="Photo with id 2" /> <input name="photos[3][title]" value="Custom title" /> </form> 参数只是一个例子,就像我上面所说的那样:我不确定以这种forms发布这些值的最佳方式。 在控制器中我想要这样的东西: @photos = Photo.find( params[photos] ) @photos.each do |photo| photo.update_attributes!(params[:photos][photo] ) end

POST请求与JSON正文

我想通过PHP将博文添加到Blogger博客 。 Google提供了下面的例子。 如何使用PHP? 您可以通过发送POST请求到后期收集URI和后期JSON主体来为博客添加一篇文章: POST https://www.googleapis.com/blogger/v3/blogs/8070105920543249955/posts/ Authorization: /* OAuth 2.0 token here */ Content-Type: application/json { "kind": "blogger#post", "blog": { "id": "8070105920543249955" }, "title": "A new post", "content": "With <b>exciting</b> content…" }

Chrome:发布数据的来源?

我使用开发人员工具使用Chrome 15来调查HTTP POST请求。 在发送请求之后,在标题下的networking选项卡中有一个称为表单数据的部分。 本部分包含很好地格式化的发布数据。 但是:如何获得发布数据的来源,即请求的主体? 目前,我使用Firefox与Firebug来获取数据,或者我从格式化的表单数据重build源。 繁琐…

使用PHP读取JSON POST

在发布这个问题之前,我环视了很多,所以我很抱歉,如果它在另一个post,这只是我在这里的第二个问题,所以道歉,如果我不正确格式化这个问题。 我有一个非常简单的Web服务,我已经创build需要采取后值,并返回一个JSON编码数组。 这一切都工作得很好,直到我被告知我需要张贴表单数据的内容types的应用程序/ JSON。 从那时起,我不能从Web服务返回任何值,这绝对是我如何过滤他们的后值。 基本上在我的本地设置,我已经创build了一个testing页面,执行以下操作 – $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data)) ); curl_setopt($curl, CURLOPT_URL, 'http://webservice.local/'); // Set the url path we want to call $result = curl_exec($curl); //see the results $json=json_decode($result,true); curl_close($curl); print_r($json); 在web服务我有这个(我已经剥离了一些function) – <?php header('Content-type: application/json'); […]

用PHP接收JSON POST

我试图在支付界面网站上收到JSON POST,但我无法解码。 当我打印时: echo $_POST; 我得到: Array 当我尝试这个时,我什么也得不到: if ( $_POST ) { foreach ( $_POST as $key => $value ) { echo "llave: ".$key."- Valor:".$value."<br />"; } } 当我尝试这个时,我什么也得不到: $string = $_POST['operation']; $var = json_decode($string); echo $var; 当我尝试这个时,我得到NULL: $data = json_decode( file_get_contents('php://input') ); var_dump( $data->operation ); 当我这样做时: $data = json_decode(file_get_contents('php://input'), true); var_dump($data); 我得到: NULL […]