UE5 UC++流式请求 || Varest流式调用Coze(但一次性回复,不太推荐)

++文章仅供参考。C++调用的是公司后台的接口,博主未尝试用C++调用Coze的接口,需要补充更多的代码。++

------------

C++

cpp 复制代码
#include "HttpModule.h"
#include "HttpManager.h"
#include "Http.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMyCustomEventDelegate, FString, Str1);
public:
	UPROPERTY(BlueprintAssignable, Category = "MyHTTP2")
		FMyCustomEventDelegate StreamingRequestBindEvent;
cpp 复制代码
void UBPC_CJiaJia_streamRequest_V01::StartStreamingRequest(const FString& Url, const FString& Question)
{
	TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
	HttpRequest->SetVerb("GET"); // 设置请求方法为GET
	HttpRequest->SetURL(Url); // 设置请求的URL
	HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("text/event-stream")); // 设置请求头

	// 请求中返回
	//HttpRequest->OnRequestProgress().BindLambda([this](FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived) {
	//		FString ContentString = Request->GetResponse()->GetContentAsString();
	//		this->StreamingRequestBindEvent.Broadcast(ContentString);
	//	}
	//);

	// 请求结束返回
	HttpRequest->OnProcessRequestComplete().BindLambda([this](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) {
		if (bWasSuccessful) {
			this->StreamingRequestBindEvent.Broadcast(Response->GetContentAsString());
		}
		}
	);

	// 开始处理请求
	HttpRequest->ProcessRequest();
}

请求时,网址+?+参数

Varest

参考网址
扣子 - 开发指南 (coze.cn)创建会话
扣子 - 开发指南 (coze.cn)发起会话

++不太推荐原因是,Varest好像只能做到整段返回++

创建会话

对话

相关推荐
子燕若水5 分钟前
“Daz to Unreal”将 G8 角色(包括表情)从 daz3d 导入到 UE5。在 UE5 中,我发现使用某个表情并与闭眼混合后,上眼睑出现了问题
3d·ue5
吴_知遇24 分钟前
【华为OD机试真题】428、连续字母长度 | 机试真题+思路参考+代码解析(E卷)(C++)
开发语言·c++·华为od
LaoWaiHang41 分钟前
MFC案例:使用键盘按键放大、缩小窗口图像的实验
c++·mfc
到底怎么取名字不会重复1 小时前
Day10——LeetCode15&560
c++·算法·leetcode·哈希算法·散列表
陈大大陈2 小时前
基于 C++ 的用户认证系统开发:从注册登录到Redis 缓存优化
java·linux·开发语言·数据结构·c++·算法·缓存
纪元A梦2 小时前
华为OD机试真题——通过软盘拷贝文件(2025A卷:200分)Java/python/JavaScript/C++/C语言/GO六种最佳实现
java·javascript·c++·python·华为od·go·华为od机试题
刚入坑的新人编程2 小时前
C++多态
开发语言·c++
QUST-Learn3D3 小时前
高精度并行2D圆弧拟合(C++)
开发语言·c++
明月醉窗台3 小时前
Qt 入门 6 之布局管理
c语言·开发语言·c++·qt
云小逸3 小时前
【C++】继承
开发语言·c++