我正在向服务器发送请求,该服务器正在处理请求和响应.但是在我的应用程序上,我收到:
Error Domain=NSURLErrorDomain Code=-1017 "cannot parse response" UserInfo=0x167668d0
{NSErrorFailingURLStringKey=https://***, _kCFStreamErrorCodeKey=-1,
NSErrorFailingURLKey=https://***/, NSLocalizedDescription=cannot
parse response, _kCFStreamErrorDomainKey=4, NSUnderlyingError=0x16731990 "cannot parse
response"
Run Code Online (Sandbox Code Playgroud)
http请求中的Accept字段就足够了.
我甚至无法看到messege到达了什么,因为NSHTTPURLResponse对象为null.
什么是一个问题,以什么方式我可以看到什么消息不会使用wireshark之类的东西.
谢谢!
我遇到过这样的说法:
"以函数式编程使得状态显示给你的代码,这使得更容易推理,并且在完全纯粹的系统中,使线程竞争条件变得不可能."
我看到了这个观点,但我怎样才能在现实世界中解决这个问题呢?
例如:
有一个功能程序有两个功能:
def getMoney(actMoney: Integer, moneyToGet: Integer): Integer
= actMoney - moneyToGet
def putMoney(actMoney: Integer, moneyToPut: Integer): Integer
= actMoney + moneyToPut
Run Code Online (Sandbox Code Playgroud)
然后,我真的想为给定的帐户定义函数getActualMoney和saveActualMoney,但我不能,它们不是纯粹的.那是因为我从一些内存中获取给定帐户的Money,并且将给定帐户的Money存入某些内存(存在状态).
def getActualMoney(accountNo: String): Integer = {...}
def saveActualMoney(accountNo: String, actMoney: Integer): Unit = {...}
Run Code Online (Sandbox Code Playgroud)
因此,我必须从"外部"获取当前的资金.让我们说,我的程序正在以这种方式工作.现在我有两个同时请求,第一个:获得一些钱,第二个为同一个帐户存入一些钱.当然,我会得到两个不同的结果.所以有竞争条件.
我明白,我应该在这个帐户"外部"编程代码上进行交易.所以,这种情况不应该发生.为了更好的并发性,函数应如下所示:
def getMoney(
acountNo: String,
actMoney: Integer,
moneyToGet: Integer): (String, Integer)
= (acountNo, actMoney - moneyToGet)
def putMoney(
acountNo: String,
actMoney: Integer,
moneyToPut: Integer): (String, Integer)
= (acountNo, actMoney + moneyToPut)
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?值得做吗?
我有一个基类,我不想让派生类可复制.为了使一切都明确,我以这种方式实现它:
class A {
public:
A() = default;
virtual ~A() = default;
A(const A&) = delete;
A(const A&&) = delete;
A& operator=(const A&) = delete;
A& operator=(const A&&) = delete;
virtual void vFun() = 0;
};
class B : public A {
public:
B() = default;
virtual ~B() = default;
B(const B&) = delete;
B(const B&&) = delete;
B& operator=(const B&) = delete;
B& operator=(const B&&) = delete;
virtual void vFun() override {}
};
Run Code Online (Sandbox Code Playgroud)
这是做这种事的正确方法吗?根据我的知识和我所读到的,答案是肯定的,但我想在将其引入生产系统之前确定.
总结一下:1)几乎总是不应删除运算符.那是因为"有无限的东西需要可动性".2)对于抽象基类,允许编译器生成特殊成员函数更安全,并且如果存在这种必要性,则将删除移动到派生类中.
我拿了一个指针m_room(类ServicePage中的Room*m_room,其中updateRoom和addService函数是)
void ServicePage::updateRoom(QString _text)
{
m_room = m_reservation->findRoom(_text.toInt());
qDebug()<<m_room;
qDebug() << m_room->m_idRoom;
}
Run Code Online (Sandbox Code Playgroud)
从
Room *Reservation::findRoom(int _id)
{
QVector<Room>::iterator iterator;
for(iterator = mv_addRooms.begin(); iterator != mv_addRooms.end(); iterator++)
if(iterator->m_idRoom == _id)
{
qDebug()<<_id;
Room _temp = *iterator;
return &_temp;
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
和qDebug之后的答案还可以,但是当我以后拿qDebug回答不同的功能时:
bool ServicePage::addService()
{
qDebug()<<m_room;
qDebug()<<m_room ->m_idRoom;
return true;
}
Run Code Online (Sandbox Code Playgroud)
m_room与之前相同,但m_room-> m_idRoom返回不同的值(随机值),为什么会这样?
谢谢你的任何建议.
我一直认为属性就像方法的捷径.然而这个例子让我很奇怪.在我看来,函数changePropertyId和changeMethodId也是这样做的.然而现实却不同.只有第二个正常工作.有人可以解释一下吗?
class Program
{
static void Main(string[] args)
{
User user = new User();
user.changePropertyId(1);
Console.Write(user.Id);
user.changeMethodId(1);
Console.Write(user.Id);
Console.ReadLine();
}
}
public class DBObject
{
private int mId;
public int Id { set { mId = Id; } get { return mId; } }
public void setId(int aId)
{mId = aId;}
}
public class User : DBObject
{
public void changePropertyId(int aId) { Id = aId; }
public void changeMethodId(int aId) { setId(aId); }
}
Run Code Online (Sandbox Code Playgroud)
第一个函数的结果是0,第二个函数的结果是1.我的目的是从两个函数得到1.
c++ ×2
afnetworking ×1
c# ×1
c++11 ×1
concurrency ×1
ios8 ×1
pointers ×1
properties ×1
qt ×1
rule-of-zero ×1