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好像只能做到整段返回++

创建会话

对话

相关推荐
云深处@3 分钟前
【C++11】部分特性
开发语言·c++
独望漫天星辰8 分钟前
C++ 树结构进阶:从工程化实现到 STL 底层与性能优化
开发语言·c++
HellowAmy12 分钟前
我的C++规范 - 鸡蛋工厂
开发语言·c++·代码规范
仰泳的熊猫17 分钟前
题目1453:蓝桥杯历届试题-翻硬币
数据结构·c++·算法·蓝桥杯
rainbow688917 分钟前
C++STL list容器模拟实现详解
开发语言·c++·list
会叫的恐龙19 分钟前
C++ 核心知识点汇总(第11日)(排序算法)
c++·算法·排序算法
符哥200830 分钟前
C++ 适合初学者的学习笔记整理
c++·笔记·学习
AI视觉网奇39 分钟前
blender 导入fbx 黑色骨骼
学习·算法·ue5·blender
星火开发设计41 分钟前
this 指针:指向对象自身的隐含指针
开发语言·数据结构·c++·学习·指针·知识
梵刹古音41 分钟前
【C++】构造函数
开发语言·c++