cUrl打开多个URL(cUrl multiple URL open)
$query = 'SELECT * FROM `chat` LIMIT 0, 24334436743;'; $result = mysql_query($query); while($row = mysql_fetch_array( $result )) { $URL = $row['url']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"$URL"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($ch, CURLOPT_POSTFIELDS, "user=unrevoked clarity&randominfo=hi"); curl_exec ($ch); curl_close ($ch); } //curl_close ($ch); }
好吧,上面的片段是我从数据库中提取了一大堆URL,我正在尝试向每个URL发送数据。 但它似乎打破了页面(即使只有一个或两个URL)。 是否有内置系统来处理这个或什么?
$query = 'SELECT * FROM `chat` LIMIT 0, 24334436743;'; $result = mysql_query($query); while($row = mysql_fetch_array( $result )) { $URL = $row['url']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"$URL"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($ch, CURLOPT_POSTFIELDS, "user=unrevoked clarity&randominfo=hi"); curl_exec ($ch); curl_close ($ch); } //curl_close ($ch); }
Alright the above snippet is me pulling a whole bunch of URL's from a database and I am trying to send data to each of them. But it seems to gum the page up (even with only one or two URL's). Is there a built in system to handle this or something?
原文:https://stackoverflow.com/questions/5215157
最满意答案
我在我的个人项目中使用JSON.NET,但是使用方括号语法反序列化,如下所示:
Id = jsonResult["object_id"].ToObject<int>(),
要实际获取JSON对象,我执行此操作:
var response = await client.GetStringAsync(parameters); var jsonResult = JToken.Parse(response)["results"].Children();
在对使用JSON.NET的不同方法进行了大量研究之后,我采用了这种方法。 阅读本文后,我认真考虑走动态路线: http : //www.west-wind.com/weblog/posts/2012/Aug/30/Using-JSONNET-for-dynamic-JSON-parsing
但是,最后我决定不使用动态对象,因为当我使用方括号语法填充我的普通对象时,我立即返回强类型环境,其中intellisense将开始捕获我可能犯的任何错误。 我将它与LINQ查询结合起来,并在相对较少的行中填充一组相当复杂的对象。
对我来说,动态对象是反序列化过程中的一个弱类型步骤,我希望尽可能避免。
I use JSON.NET in a personal project of mine, but deserialize using square bracket syntax like this:
Id = jsonResult["object_id"].ToObject<int>(),
To actually get the JSON object I do this:
var response = await client.GetStringAsync(parameters); var jsonResult = JToken.Parse(response)["results"].Children();
I adopted this methodology after doing a good bit of research into the different ways to use JSON.NET. I seriously considered going the dynamic route after reading this article: http://www.west-wind.com/weblog/posts/2012/Aug/30/Using-JSONNET-for-dynamic-JSON-parsing
However, in the end I decided against dynamic objects because when I fill my normal objects with the square bracket syntax I return immediately to a strongly-typed environment where intellisense will begin to catch any errors I may make. I combine this with a LINQ query and fill a set of fairly complex objects in a relatively few number of lines.
For me, dynamic objects are one more weakly-typed step in the deserialization process that I prefer to avoid if possible.
相关问答
更多-
使用具有相同变量的varing数据类型序列化JSON(Serializing JSON with varing datatype with the same variable)[2023-04-15]
对json字符串或数组使用相同字段的最简单方法可能是使用Object字段。 此解决方案不需要自定义序列化程序和反序列化程序。 以下是Jackson注释的示例类: @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) public class NetworkStatistics { private String apiVersion; private String latitude; private Stri ... -
反序列化Json数据类型文件(Deserialize Json Datatype File)[2022-11-02]
我的假设是错误的,我已经打印了Json。 我刚刚发布了javascript对象。 至于无法发送它是因为我的html表单中的multipart / formdata发送它通过restangular它变成application / json。 在这个重新讨论的问题上,我发现了如何在Formdata中打包它。 My assumption that was wrong that I was already printing the Json. I was just posting the javascript ob ... -
将ExternalUrls声明为 [JsonProperty("external_urls")] public Dictionary
ExternalUrls { get; set; } declare ExternalUrls as [JsonProperty("external_urls")] public Dictionary ExternalUrls { get; set; } -
在没有类或任何数据类型的json中反序列化json结果(Deserialize json result with in a json without a class or any datatype)[2021-07-05]
你的JSON是什么样的? {"Filter": "[{'Vehicle':'5010','Users':'2279'}]"} 要么 [{'Vehicle':'5010','Users':'2279'}] 要么 {[Filter, [{'Vehicle':'5010','Users':'2279'}]]} ??? 例如,您可以尝试这样的事情: //JSON looks like this {"Filter": "[{'Vehicle':'5010','Users':'2279'}]"} var jso ... -
橡胶与同事一起解决这个问题后,上述行为对我来说是有道理的。 在不知道它反序列化的对象类型的情况下,Json.Net真的无法知道Sons或Bros属性不是包含“{”$ ref“:”1“}”的字符串属性......怎么可能呢? 当然它反错误地反序列化了。 它必须知道目标类型,以便知道何时进一步反序列化对象的属性。 最终得到一个动态对象,其字符串属性包含对象引用的Json表示。 当模型绑定器尝试使用此动态对象在具体类型上设置值时,它找不到匹配项,并且最终得到目标的空实例。 Jason Butera对这个问题的回答 ...
-
将WinJS绑定到WinRT对象(Binding WinJS to WinRT objects)[2023-02-27]
不,如果没有创建自己的包装器,这是不可能的: “代理”WinRT对象,并使该代理侦听来自WinRT对象的事件并设置属性 从WinRT层创建看起来像可观察和投射的东西(例如,它具有“绑定”功能,可以进行回调等。 No, this isn't possible without creating your own wrapper that would either: "Proxy" the WinRT object, and make that proxy listen for events from the W ... -
我在我的个人项目中使用JSON.NET,但是使用方括号语法反序列化,如下所示: Id = jsonResult["object_id"].ToObject
(), 要实际获取JSON对象,我执行此操作: var response = await client.GetStringAsync(parameters); var jsonResult = JToken.Parse(response)["results"].Children(); 在对使用JSON.NET的不同方法进行了大量研究之后,我采 ... -
您的网址似乎返回压缩数据,HttpClient不知何故不理解这一点。 下面的代码修复了这个: public static async Task
GetJsonString() { HttpClient client = new HttpClient(); string url = @"https://api.stackexchange.com/2.1/answers?fromdate=1349913600&order=desc&min=20&sort=votes&site=s ... -
创建一个像itemInfo这样的子结构: type itemInfo struct { Stat string `json:"stat"` Crit int `json:"crit"` } 然后在你的Item结构中 type Item struct { --snip-- Context string `gorm:"column:context" json:"context"` Stats []itemInfo `gorm:"column:stats" json ...
-
关于我的评论,也许我们最好写下我的例子: string json = @"{""ABC"": 123, ""DEF"": 234}"; var employees = JsonConvert.DeserializeObject
>(json).Select(x => new Employees() { employeeCode = x.Key, cityId = x.Value }); Regarding my comment maybe it us be ...