我试图使用fsockopen发布数据,然后返回结果.这是我目前的代码:
<?php
$data="stuff=hoorah\r\n";
$data=urlencode($data);
$fp = fsockopen("www.website.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "POST /script.php HTTP/1.0\r\n";
$out .= "Host: www.webste.com\r\n";
$out .= 'Content-Type: application/x-www-form-urlencoded\r\n';
$out .= 'Content-Length: ' . strlen($data) . '\r\n\r\n';
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
Run Code Online (Sandbox Code Playgroud)
它应该回显页面,它回显页面,但这里是script.php的脚本
<?php
echo "<br><br>";
$raw_data = $GLOBALS['HTTP_RAW_POST_DATA'];
parse_str( $raw_data, $_POST );
//test 1
var_dump($raw_data);
echo "<br><br>":
//test 2
print_r( $_POST );
?> …Run Code Online (Sandbox Code Playgroud) 在自定义中ActionFilter,我想检查将要执行的控制器操作的属性.运行一个小型测试应用程序,以下工作在asp.net开发服务器中启动应用程序时 -
public class CustomActionFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var someAttribute = filterContext.ActionDescriptor
.GetCustomAttributes(typeof(SomeAttribute), false)
.Cast<SomeAttribute>()
.SingleOrDefault();
if (someAttribute == null)
{
throw new ArgumentException();
}
// do something here
}
public override void OnActionExecuted(ActionExecutingContext filterContext)
{
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
一个没有SomeAttribute抛出的动作方法ArgumentException,相反,一个动作方法没有抛出SomeAttribute.到现在为止还挺好.
现在我想为ActionFilter设置一些单元测试,但是如何设置OnActionExecuting方法应该在单元测试中运行的action方法?使用以下代码找不到SomeAttribute将要执行的操作方法.测试设置正确吗?我没有在测试中正确安排一些东西吗?澄清一下,测试并不完整,但我不确定我错过了什么,以便someAttribute在OnActionExecuting测试中null
[TestMethod]
public void Controller_With_SomeAttribute()
{
FakeController fakeController =
new FakeController();
ControllerContext controllerContext =
new ControllerContext(new …Run Code Online (Sandbox Code Playgroud) 对于在另一个内部调用的类,有没有办法知道外部类的名称?
例:
class A{
// need to get the name of B
// some stuff
}
class B{
$var = new A;
}
Run Code Online (Sandbox Code Playgroud)
get_parent_class()由于B不是A的孩子,所以不做这项工作.
有什么建议?
编辑:对不起大家我不得不改变这个问题.我想问的是,A类可以知道调用它的类的名称.再次抱歉愚蠢的第一个问题.
也许有一个适当的术语,但是如果你想简单地将文件/目录的特定版本下载到磁盘并且永远不想提交任何更改 - 比如作为构建/发布过程的一部分 - 并且你没有想要SVN元信息.
对此有简单的命令吗?这是出口的吗?或者是处理"un-SVNing"现有结账?
我想在我的Android应用程序中将音量按钮用于其他内容.我被告知海豚浏览器这样做.谁知道怎么样?
所以我有 3 个不同的列(篮 1、2 和 3)。有时这些列包含所有信息,有时其中一两个为空。我还有另一列,我要将这些值平均并保存。
即使其中一列为空,是否有一种时尚/简单的方法来获得这三列的平均值?或者我是否必须对每个为空的人进行特殊检查?
示例数据(~~为空)
- B1 - B2 - B3 - Avg
------------------------------
- 10 - 20 - 30 - 20
- 10 - ~~ - 30 - 20
- ~~ - 20 - ~~ - 20
Run Code Online (Sandbox Code Playgroud)
我将如何编写 T-SQL 来更新我的临时表?
UPDATE @MyTable
SET Avg = ???
Run Code Online (Sandbox Code Playgroud)
答:感谢 Aaronaught 为我使用的方法。我将把我的代码放在这里,以防其他人有同样的事情。
WITH AverageView AS
(
SELECT Results_Key AS xxx_Results_Key,
AVG(AverageValue) AS xxx_Results_Average
FROM @MyResults
UNPIVOT (AverageValue FOR B IN (Results_Basket_1_Price, Results_Basket_2_Price, Results_Basket_3_Price)) AS UnpivotTable
GROUP BY Results_Key
) …Run Code Online (Sandbox Code Playgroud) 我在使用带有std :: map的自定义类时遇到问题.该类为成员动态分配内存,我不想在地图中使用指针,因为我想确保该类负责删除所有已分配的内存.但我遇到的问题是在我将项目添加到map之后,当该代码块超出范围时,即使它仍然在地图上,也会调用对象析构函数.我在下面做了一些假代码,显示了我的意思.输出是:所以问题是为什么最后的析构函数被调用?在此先感谢并为长期问题感到抱歉.
Constructor Called Num:0034B7E8
Default Constructor Called Num:00000000
Copy Constructor Called Num:CCCCCCCC
Copy Constructor Called Num:CDCDCDCD
destructor called Num:CCCCCCCC
destructor called Num:00000000
destructor called Num:0034B7E8
Inserted Num:0034B7E8
class myClass
{
public:
myClass(int num)
{
mnNum = new int();
cout << "Constructor Called Num:" << mnNum << endl;
}
myClass() : mnNum(NULL)
{
cout << "Default Constructor Called Num:" << mnNum << endl;
}
myClass(const myClass ©)
{
mnNum = new int(copy.mnNum);
cout << "Copy Constructor Called Num:" << …Run Code Online (Sandbox Code Playgroud) 我刚刚发布了这个问题并了解了<see cref="">,但是当我尝试的时候
/// This is a set of extensions that allow more operations on a <see cref="byte[]"/>.
Run Code Online (Sandbox Code Playgroud)
编译器给了我关于它没有正确格式化的警告.我需要做什么才能正确看到代码引用?
在Java中,每当创建内部类实例时,它都与外部类的实例相关联.出于好奇,是否可以将内部类与外部类的另一个实例相关联?